diff --git a/load_schedule.py b/load_schedule.py old mode 100644 new mode 100755 index 9e6e980..3d52480 --- a/load_schedule.py +++ b/load_schedule.py @@ -11,7 +11,7 @@ if __name__ == '__main__': # Create the table cur.execute("""create table schedule( id integer primary key, """ + - """title, session_type, date_start INTEGER,""" + + """title, session_type, date_start,""" + """location, round );""") con.commit() @@ -24,14 +24,10 @@ if __name__ == '__main__': "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]) + (row) ) con.commit() cur.close() - con.close() \ No newline at end of file + con.close() diff --git a/robottas.py b/robottas.py index 7a067fe..d5440bd 100755 --- a/robottas.py +++ b/robottas.py @@ -532,49 +532,63 @@ class Robottas(commands.Bot): return 'Watched Already' - async def report_next_event(self,ctx): + async def report_next_event(self, ctx): try: + + tz = datetime.timezone.utc 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 + 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: - ctx.send("Sorry, hit the wall trying to find the answer...") + await ctx.send("Sorry, hit the wall trying to find the answer...") - async def report_next_race(self,ctx): + async def report_next_race(self, ctx): try: + tz = datetime.timezone.utc 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 + 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: - ctx.send("Sorry, hit the wall trying to find the answer...") + await ctx.send("Sorry, hit the wall tring to find the next race.") + def __init__(self): # Set debug or not