-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_menu.py
95 lines (65 loc) · 2.02 KB
/
parse_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
parse_menu.py
Gets menu from google sheet, parses into json format, and returns it to the API
"""
import gspread
import helper
from datetime import date, timedelta
from credentials import *
import json
import helper
def determine_chef(chef) -> str:
# check who is cooking (ALL, JAC, JP, JT, JK)
decoded_chef = chef
for inits in initials:
if chef.startswith(inits):
decoded_chef = initials[inits]
break
return decoded_chef
def main():
# Authenticate with google
gc = gspread.service_account(filename="service_account.json")
# Open the sheet
sh = gc.open_by_url("https://docs.google.com/spreadsheets/d/1Zck-jr2AarnekU2aEVZ2758NqdLvZ_zzRvqmzR2s704/edit#gid=1048819164")
worksheet = sh.worksheet("Meal Plan")
values = worksheet.get_all_values()
# Remove the header row
values.pop(0)
# Get today's date
today_date = helper.getDateToday()
# Calculate days since 13 Feb 2024 as a timedelta object
row_index = (today_date - date(2024, 2, 13)).days
# create json list
menu = []
# Loop through 3 days
for i in range(3):
# Get the day's row
row = values[row_index]
chef = row[1]
dinner = row[2]
notes = row[3]
people_info = row[4]
shopping = row[5]
person = determine_chef(chef)
# Determine date
day_of_week = today_date.strftime("%A")
day = str(int(today_date.strftime("%d")))
suffix = helper.get_ordinal_suffix(int(day))
# Create the json object
day_data = {
"date": f"{day_of_week} {day}{suffix}",
"chef": person,
"dinner": dinner,
"notes": notes,
"people_info": people_info,
"shopping": shopping,
}
menu.append(day_data)
row_index+=1
today_date += timedelta(1)
# print(menu)
json_menu = json.dumps(menu)
return json_menu
if __name__ == '__main__':
json_menu = main()
print(json_menu)