robottas/load_schedule.py

34 lines
941 B
Python
Executable File

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()