update,
This commit is contained in:
52
vihuwach/task1/archive/task2c.py
Normal file
52
vihuwach/task1/archive/task2c.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# get_todayinfo(js_row, ph_dates)
|
||||
# get_todayinfo(js_row, ph_dates, '2024-12-25')
|
||||
|
||||
import datetime
|
||||
import json
|
||||
from pprint import pprint
|
||||
|
||||
js_row = {}
|
||||
with open('spices.json') as f:
|
||||
js_row = json.load(f)
|
||||
|
||||
ph_dates = [
|
||||
'2024-10-18',
|
||||
]
|
||||
|
||||
def get_todayinfo(js_row, ph_dates, today_date_str = datetime.datetime.today().strftime('%Y-%m-%d')):
|
||||
given_date = datetime.datetime.strptime(today_date_str, '%Y-%m-%d')
|
||||
weekdays = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
|
||||
txt_weekday = "PH" if today_date_str in ph_dates else weekdays[given_date.weekday()]
|
||||
pprint((today_date_str,ph_dates,txt_weekday))
|
||||
|
||||
output = {
|
||||
'periodStart': '',
|
||||
'periodEnd': '',
|
||||
'price': 0,
|
||||
'space': 0,
|
||||
'today': today_date_str,
|
||||
'today_weekday': txt_weekday
|
||||
}
|
||||
|
||||
if (js_row.get('privateCar') != None):
|
||||
jp = js_row['privateCar']
|
||||
if (jp.get('space') != None):
|
||||
output['space'] = js_row['privateCar']['space']
|
||||
if (jp.get('hourlyCharges') != None):
|
||||
for i in js_row['privateCar']['hourlyCharges']:
|
||||
if txt_weekday in i['weekdays']:
|
||||
output['periodStart'] = i['periodStart']
|
||||
output['periodEnd'] = i['periodEnd']
|
||||
output['price'] = i['price']
|
||||
break
|
||||
|
||||
|
||||
output['today'] = today_date_str
|
||||
output['today_weekday'] = txt_weekday
|
||||
|
||||
|
||||
return output
|
||||
|
||||
pprint(get_todayinfo(js_row, ph_dates))
|
||||
pprint(get_todayinfo(js_row, ph_dates,'2024-01-01'))
|
||||
pprint(get_todayinfo(js_row, ph_dates,'2024-10-18'))
|
Reference in New Issue
Block a user