Add next_event and next_race

This commit is contained in:
tamservo
2023-12-25 15:28:15 -05:00
parent 51d5331d9d
commit e8fd9611d2
3 changed files with 113 additions and 0 deletions

37
load_schedule.py Normal file
View 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()