Compare commits

...

4 Commits

Author SHA1 Message Date
tamservo
c91c0e6e05 Fixes for time to next event / race. 2023-12-25 17:01:09 -05:00
tamservo
e960966a47 Merge branch 'main' of https://git.sdf.org/tamservo/robottas 2023-12-25 15:31:42 -05:00
tamservo
a4890aaccb commit 2023-12-25 15:31:38 -05:00
tamservo
e8fd9611d2 Add next_event and next_race 2023-12-25 15:28:15 -05:00
3 changed files with 125 additions and 0 deletions

18
2024_schedule.csv Normal file
View File

@@ -0,0 +1,18 @@
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-21 12:00:00,Bahrain,0
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-22 12:00:00,Bahrain,0
FORMULA 1 ARAMCO PRE-SEASON TESTING 2024,Practice,2024-02-23 12:00:00,Bahrain,0
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-02-29 11:30:00,Bahrain,1
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-02-29 15:00:00,Bahrain,1
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024,Practice,2024-03-01 11:30:00,Bahrain,1
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2025,Qualifying,2024-03-01 15:00:00,Bahrain,1
FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2026,Race,2024-03-02 15:00:00,Bahrain,1
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-07 13:30:00,Saudi Arabia,2
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-07 17:00:00,Saudi Arabia,2
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Practice,2024-03-08 13:30:00,Saudi Arabia,2
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Qualifying,2024-03-08 17:00:00,Saudi Arabia,2
FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024,Race,2024-03-09 17:00:00,Saudi Arabia,2
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-22 01:30:00,Australia,3
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-22 05:00:00,Australia,3
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Practice,2024-03-23 01:30:00,Australia,3
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Qualifying,2024-03-23 05:00:00,Australia,3
FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024,Race,2024-03-24 06:00:00,Australia,3
1 FORMULA 1 ARAMCO PRE-SEASON TESTING 2024 Practice 2024-02-21 12:00:00 Bahrain 0
2 FORMULA 1 ARAMCO PRE-SEASON TESTING 2024 Practice 2024-02-22 12:00:00 Bahrain 0
3 FORMULA 1 ARAMCO PRE-SEASON TESTING 2024 Practice 2024-02-23 12:00:00 Bahrain 0
4 FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024 Practice 2024-02-29 11:30:00 Bahrain 1
5 FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024 Practice 2024-02-29 15:00:00 Bahrain 1
6 FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2024 Practice 2024-03-01 11:30:00 Bahrain 1
7 FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2025 Qualifying 2024-03-01 15:00:00 Bahrain 1
8 FORMULA 1 GULF AIR BAHRAIN GRAND PRIX 2026 Race 2024-03-02 15:00:00 Bahrain 1
9 FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024 Practice 2024-03-07 13:30:00 Saudi Arabia 2
10 FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024 Practice 2024-03-07 17:00:00 Saudi Arabia 2
11 FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024 Practice 2024-03-08 13:30:00 Saudi Arabia 2
12 FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024 Qualifying 2024-03-08 17:00:00 Saudi Arabia 2
13 FORMULA 1 STC SAUDI ARABIAN GRAND PRIX 2024 Race 2024-03-09 17:00:00 Saudi Arabia 2
14 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024 Practice 2024-03-22 01:30:00 Australia 3
15 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024 Practice 2024-03-22 05:00:00 Australia 3
16 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024 Practice 2024-03-23 01:30:00 Australia 3
17 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024 Qualifying 2024-03-23 05:00:00 Australia 3
18 FORMULA 1 ROLEX AUSTRALIAN GRAND PRIX 2024 Race 2024-03-24 06:00:00 Australia 3

33
load_schedule.py Executable file
View File

@@ -0,0 +1,33 @@
import csv
import datetime
import sqlite3
if __name__ == '__main__':
con = sqlite3.connect('schedule.db')
cur = con.cursor()
cur.execute("""drop table schedule""")
# Create the table
cur.execute("""create table schedule( id integer primary key, """ +
"""title, session_type, date_start,""" +
"""location, round );""")
con.commit()
# Open the csv file
with open("2024_schedule.csv") as csvfile:
schedule_reader = csv.reader(csvfile, )
for row in schedule_reader:
sql_line = "INSERT INTO schedule (title, session_type, " + \
"date_start, location, round) VALUES(" + \
f"?, ?, ?, ?, ?)"
cur.execute(sql_line,
(row)
)
con.commit()
cur.close()
con.close()

View File

@@ -2,6 +2,7 @@
import asyncio
import collections.abc
import datetime
import json
import os
import random
@@ -377,6 +378,8 @@ class Robottas(commands.Bot):
driver = '???'
if driver_num in self.driver_dict.keys():
driver = self.driver_dict[driver_num]
else:
driver = driver_num
#self.driver_list[int(position) - 1] = self.driver_dict[driver_num]
self.driver_list[int(position) - 1] = driver
@@ -527,6 +530,65 @@ class Robottas(commands.Bot):
return 'Not Watched Yet'
else:
return 'Watched Already'
async def report_next_event(self, ctx):
try:
tz = datetime.timezone.utc
con = sqlite3.connect('schedule.db')
cur = con.cursor()
now_str = datetime.datetime.now(tz=tz).isoformat(sep=' ')
now_str = now_str.split(".")[0]
query = 'select * from schedule where date_start > ? ' + \
'order by date_start asc limit 1'
cur.execute(query, (now_str,))
rows = cur.fetchall()
for row in rows:
t1 = datetime.datetime.fromisoformat(now_str)
t2 = datetime.datetime.fromisoformat(row[3])
delta = t2 - t1
message = f"The next event is the {row[1]} which is {delta} from now."
await ctx.send(message)
break # There should only be one row anyway
except:
await ctx.send("Sorry, hit the wall trying to find the answer...")
async def report_next_race(self, ctx):
try:
tz = datetime.timezone.utc
con = sqlite3.connect('schedule.db')
cur = con.cursor()
now_str = datetime.datetime.now(tz=tz).isoformat(sep=' ')
now_str = now_str.split(".")[0]
query = "SELECT * FROM schedule WHERE date_start > ? AND " + \
"session_type = 'Race' ORDER BY date_start ASC LIMIT 1"
cur.execute(query, (now_str,))
rows = cur.fetchall()
for row in rows:
t1 = datetime.datetime.fromisoformat(now_str)
t2 = datetime.datetime.fromisoformat(row[3])
delta = t2 - t1
message = f"The next race is the {row[1]} which is {delta} from now."
await ctx.send(message)
break
except:
await ctx.send("Sorry, hit the wall tring to find the next race.")
def __init__(self):
# Set debug or not
@@ -900,6 +962,18 @@ class Robottas(commands.Bot):
async def undercut(ctx):
await self.send_image(ctx, "images/undercut.png")
## Calendar Commands
# Give days, hours, minutes until the next event
@self.command()
async def next_event(ctx):
await self.report_next_event(ctx)
# Give days, hours, minutes until the next race
@self.command()
async def next_race(ctx):
await self.report_next_race(ctx)
if __name__ == '__main__':
rb = Robottas()