Skip to content

Commit 8970b0c

Browse files
committed
ask input for filenames
1 parent f70fb0b commit 8970b0c

File tree

6 files changed

+69
-28
lines changed

6 files changed

+69
-28
lines changed

generate_quote_audio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from pydub import AudioSegment
55
from io import BytesIO
66

7-
with open("data/final schedule with uuids.csv", encoding="utf-8") as scheduleFile:
7+
filename = input("Enter data filename (default: contacts.csv): ") or "contacts.csv"
8+
with open("data/{}".format(filename), encoding="utf-8") as scheduleFile:
89
graduates = [
910
{k: v for k, v in row.items()}
1011
for row in csv.DictReader(scheduleFile, skipinitialspace=True)

generate_schedule.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def comparer(left, right):
3636

3737

3838
# load data then sort by descending timezone and ascending school within timezone
39-
with open("data/school timezones.csv", encoding="utf-8") as schoolTimezonesFile:
39+
filename = input("Enter timezones filename (default: school timezones.csv): ") or "school timezones.csv"
40+
with open("data/{}".format(filename), encoding="utf-8") as schoolTimezonesFile:
4041
data = [
4142
{k: v if k == "School" else float(v) for k, v in row.items()}
4243
for row in csv.DictReader(schoolTimezonesFile, skipinitialspace=True)
@@ -124,7 +125,8 @@ def __eq__(self, other):
124125
print(dupes)
125126

126127
# now to order students
127-
with open("data/HS - Master RSVPs.csv", encoding="utf-8") as rsvpFile:
128+
filename = input("Enter contacts filename (default: contacts.csv): ") or "contacts.csv"
129+
with open("data/{}".format(filename), encoding="utf-8") as rsvpFile:
128130
rsvps = [
129131
{k: v for k, v in row.items()}
130132
for row in csv.DictReader(rsvpFile, skipinitialspace=True)
@@ -220,8 +222,9 @@ def __eq__(self, other):
220222
print(tabulate(print_order, headers="keys"))
221223

222224
# save utc student schedule
225+
filename = input("Enter student schedule filename (default: student schedule utc.csv): ") or "student schedule utc.csv"
223226
with open(
224-
"data/student schedule utc.csv", "w", encoding="utf-8", newline=""
227+
"data/{}".format(filename), "w", encoding="utf-8", newline=""
225228
) as studentScheduleFile:
226229
csvFields = list(pretty_order[0].keys())
227230
writer = csv.DictWriter(studentScheduleFile, fieldnames=csvFields)

import_sql.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
cursorclass=pymysql.cursors.DictCursor,
1919
)
2020

21-
with open("data/final schedule with uuids.csv", encoding="utf-8") as scheduleFile:
21+
filename = input("Enter data filename (default: contacts.csv): ") or "contacts.csv"
22+
with open("data/{}".format(filename), encoding="utf-8") as scheduleFile:
2223
graduates = [
2324
{k: v for k, v in row.items()}
2425
for row in csv.DictReader(scheduleFile, skipinitialspace=True)

merge_schedule_with_contacts.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
PRINT_TABULATE = False
88
SHOW_VIS = False
9+
SAVE_SCHOOL_CSV = True
10+
SAVE_SCHOOL_HTML = True
911

1012
# load clustered schedule (make sure you go make that first in google sheets)
11-
with open("data/student schedule utc clustered.csv", encoding="utf-8") as file:
13+
filename = input("Enter clustered schedule filename (default: student schedule utc clustered.csv): ") or "student schedule utc clustered.csv"
14+
with open("data/{}".format(filename), encoding="utf-8") as file:
1215
data = [
1316
{k: v for k, v in row.items()}
1417
for row in csv.DictReader(file, skipinitialspace=True)
@@ -28,7 +31,8 @@
2831
plt.show()
2932

3033
# load original RSVPs and make map keyed by email
31-
with open("data/HS - Master RSVPs.csv", encoding="utf-8") as rsvpFile:
34+
filename = input("Enter contacts filename (default: contacts.csv): ") or "contacts.csv"
35+
with open("data/{}".format(filename), encoding="utf-8") as rsvpFile:
3236
rsvps = [
3337
{k: v for k, v in row.items()}
3438
for row in csv.DictReader(rsvpFile, skipinitialspace=True)
@@ -103,21 +107,25 @@
103107
for s in schoolOrder
104108
]
105109

106-
"""# save utc school schedule
107-
with open(
108-
"data/FINAL school schedule utc.csv", "w", encoding="utf-8", newline=""
109-
) as schoolScheduleCSVFile:
110-
csvFields = ["School", "Start Time"]
111-
writer = csv.DictWriter(schoolScheduleCSVFile, fieldnames=csvFields)
112-
writer.writeheader()
113-
writer.writerows(schoolOrder)
114-
print("\n--> Saved FINAL school schedule utc CSV!")"""
110+
if SAVE_SCHOOL_CSV:
111+
# save utc school schedule
112+
filename = input("Enter school schedule CSV filename (default: school schedule utc.csv): ") or "school schedule utc.csv"
113+
with open(
114+
"data/{}".format(filename), "w", encoding="utf-8", newline=""
115+
) as schoolScheduleCSVFile:
116+
csvFields = ["School", "Start Time"]
117+
writer = csv.DictWriter(schoolScheduleCSVFile, fieldnames=csvFields)
118+
writer.writeheader()
119+
writer.writerows(schoolOrder)
120+
print("\n--> Saved FINAL school schedule utc CSV!")
115121

116-
# use tabulate to save html school schedule
117-
with open("data/school-schedule.html", "w", encoding="utf-8") as schoolScheduleHTMLFile:
118-
# schoolScheduleHTMLFile.write(tabulate(schoolOrder, headers="keys", tablefmt="html"))
119-
print(schoolOrder)
120-
print("\n--> Saved FINAL school schedule utc HTML!")
122+
if SAVE_SCHOOL_HTML:
123+
# use tabulate to save html school schedule
124+
filename = input("Enter school schedule HTML filename (default: school-schedule.html): ") or "school-schedule.html"
125+
with open("data/{}".format(filename), "w", encoding="utf-8") as schoolScheduleHTMLFile:
126+
schoolScheduleHTMLFile.write(tabulate(schoolOrder, headers="keys", tablefmt="html"))
127+
print(schoolOrder)
128+
print("\n--> Saved FINAL school schedule utc HTML!")
121129

122130
# save final dataset
123131
finalData = []
@@ -130,8 +138,9 @@
130138
student["Approx Time Zone"] = item["Time Zone"]
131139
finalData.append(student)
132140

141+
filename = input("Enter student schedule filename (default: student schedule utc.csv): ") or "student schedule utc.csv"
133142
with open(
134-
"data/FINAL student schedule utc.csv", "w", encoding="utf-8", newline=""
143+
"data/{}".format(filename), "w", encoding="utf-8", newline=""
135144
) as studentScheduleFile:
136145
csvFields = list(finalData[0].keys())
137146
writer = csv.DictWriter(studentScheduleFile, fieldnames=csvFields)

play_ceremony_audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def playAudio(filePath, name):
3030
audio = AudioSegment.from_mp3(filePath)
3131
play(audio)
3232

33-
34-
with open("data/final schedule with uuids.csv", encoding="utf-8") as scheduleFile:
33+
filename = input("Enter data filename (default: contacts.csv): ") or "contacts.csv"
34+
with open("data/{}".format(filename), encoding="utf-8") as scheduleFile:
3535
graduates = [
3636
{k: v for k, v in row.items()}
3737
for row in csv.DictReader(scheduleFile, skipinitialspace=True)

reset_timeslots.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1+
import csv
2+
import pymysql.cursors
3+
import os
4+
from datetime import datetime
5+
from dotenv import load_dotenv
16

2-
```sql
3-
SET @row_number = 0;
4-
UPDATE graduates SET timeslot = FROM_UNIXTIME(30 * (@row_number:=@row_number + 1) + UNIX_TIMESTAMP());
5-
```
7+
load_dotenv()
8+
9+
# Connect to the database
10+
connection = pymysql.connect(
11+
host=os.getenv("SQL_HOST"),
12+
user=os.getenv("SQL_USER"),
13+
password=os.getenv("SQL_PASSWORD"),
14+
db=os.getenv("SQL_DB"),
15+
charset="utf8mb4",
16+
autocommit=True,
17+
init_command="SET SESSION time_zone='+00:00'",
18+
cursorclass=pymysql.cursors.DictCursor,
19+
)
20+
21+
try:
22+
with connection.cursor() as cursor:
23+
# init temp variable
24+
sql = "SET @row_number = 0"
25+
cursor.execute(sql)
26+
27+
# use variable to update timeslots
28+
sql = "UPDATE `graduates` SET `timeslot` = FROM_UNIXTIME(30 * (@row_number:=@row_number + 1) + UNIX_TIMESTAMP()) WHERE `graduated` = 0"
29+
cursor.execute(sql)
30+
print("> Reset timeslots")
31+
finally:
32+
connection.close()

0 commit comments

Comments
 (0)