Add next_event and next_race
This commit is contained in:
parent
51d5331d9d
commit
e8fd9611d2
18
2024_schedule.csv
Normal file
18
2024_schedule.csv
Normal 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
|
|
37
load_schedule.py
Normal file
37
load_schedule.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
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 INTEGER,""" +
|
||||||
|
"""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"?, ?, ?, ?, ?)"
|
||||||
|
|
||||||
|
# Convert date into seconds
|
||||||
|
date_str = row[2]
|
||||||
|
date_obj = datetime.datetime.fromisoformat(date_str)
|
||||||
|
|
||||||
|
cur.execute(sql_line,
|
||||||
|
(row[0], row[1], date_obj.timestamp(), row[3], row[4])
|
||||||
|
)
|
||||||
|
con.commit()
|
||||||
|
|
||||||
|
cur.close()
|
||||||
|
con.close()
|
58
robottas.py
58
robottas.py
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
@ -528,6 +529,51 @@ class Robottas(commands.Bot):
|
||||||
else:
|
else:
|
||||||
return 'Watched Already'
|
return 'Watched Already'
|
||||||
|
|
||||||
|
|
||||||
|
async def report_next_event(self,ctx):
|
||||||
|
try:
|
||||||
|
con = sqlite3.connect('schedule.db')
|
||||||
|
cur = con.cursor()
|
||||||
|
now_secs = datetime.datetime.now().timestamp()
|
||||||
|
for row in cur.execute('select * from schedule ' + \
|
||||||
|
'where date_start > ?' + \
|
||||||
|
'order by date_start ascending limit 1',
|
||||||
|
(now_secs)):
|
||||||
|
next_secs = row[2]
|
||||||
|
delta_seconds = next_secs - now_secs
|
||||||
|
td = datetime.timedelta(seconds=delta_seconds)
|
||||||
|
next_date = datetime.datetime.fromtimestamp(next_secs)
|
||||||
|
message = f"Next event is {row[0]} at {next_date}. " + \
|
||||||
|
f"Time remaining {td}"
|
||||||
|
await ctx.send(message)
|
||||||
|
break # There should only be one row anyway
|
||||||
|
|
||||||
|
except:
|
||||||
|
ctx.send("Sorry, hit the wall trying to find the answer...")
|
||||||
|
|
||||||
|
|
||||||
|
async def report_next_race(self,ctx):
|
||||||
|
try:
|
||||||
|
con = sqlite3.connect('schedule.db')
|
||||||
|
cur = con.cursor()
|
||||||
|
now_secs = datetime.datetime.now().timestamp()
|
||||||
|
for row in cur.execute('select * from schedule ' + \
|
||||||
|
'where date_start > ? and ' + \
|
||||||
|
'session_type = "Race" ' + \
|
||||||
|
'order by date_start ascending limit 1',
|
||||||
|
(now_secs)):
|
||||||
|
next_secs = row[2]
|
||||||
|
delta_seconds = next_secs - now_secs
|
||||||
|
td = datetime.timedelta(seconds=delta_seconds)
|
||||||
|
next_date = datetime.datetime.fromtimestamp(next_secs)
|
||||||
|
message = f"Next event is {row[0]} at {next_date}. " + \
|
||||||
|
f"Time remaining {td}"
|
||||||
|
await ctx.send(message)
|
||||||
|
break # There should only be one row anyway
|
||||||
|
|
||||||
|
except:
|
||||||
|
ctx.send("Sorry, hit the wall trying to find the answer...")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Set debug or not
|
# Set debug or not
|
||||||
self.debug = True
|
self.debug = True
|
||||||
|
@ -900,6 +946,18 @@ class Robottas(commands.Bot):
|
||||||
async def undercut(ctx):
|
async def undercut(ctx):
|
||||||
await self.send_image(ctx, "images/undercut.png")
|
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__':
|
if __name__ == '__main__':
|
||||||
rb = Robottas()
|
rb = Robottas()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user