I'm trying to extend Python - Iterate thru month dates and print a custom output and add an addtional functionality to check if a date in the given date range is national holiday, print "NH" and that corresponding date.
Ex: 2020-05-04 & 2020-05-14 are national holidays and that date alone should be printed like
import sys
from datetime import date, datetime, timedeltayear = int(sys.argv[1])
month = int(sys.argv[2])
st_dt = int(sys.argv[3])
en_dt = int(sys.argv[4])
public_holiday = sys.argv[5].split(',')ph = []
for d in public_holiday:ph.append(date(year, month, int(d)))def daterange(startDate, endDate, delta=timedelta(days=1)):currentDate = startDatewhile currentDate <= endDate:yield currentDatecurrentDate += deltaallDays = {}
_lastDayType = Nonefor dte in daterange(date(year, month, st_dt), date(year, month, en_dt), delta=timedelta(days=1)):#print(f"sdfdsfsdf: {dte.weekday()}")if dte.weekday() < 5:_dayType = 'working'else:_dayType = 'weekend'_weeknum = dte.strftime("%V")_key = (_weeknum, _dayType)if _key not in allDays:allDays[_key] = []allDays[_key].append(dte)for k,v in allDays.items():week_end = ''gov_hol = ''if len(v) == 1:first, last = v[0], v[0]elif len(v) == 2 and k[1] == 'weekend':first, last, week_end = v[0], v[-1], 'YES'elif ph in allDays.values():gov_hol, first, last = 'NH', v[0], v[0]else:first, last = v[0], v[-1]print(f"{gov_hol}, {first} >> {last} >> {len(v)} >> {week_end}")
Input args: date.py 2020 5 1 31 "4, 14"
Currently, elif ph in allDays.values():
is not matching condition.
Current Output
2020-05-01 >> 2020-05-01 >> 1 >> >>
2020-05-02 >> 2020-05-03 >> 2 >> YES >>
2020-05-04 >> 2020-05-08 >> 5 >> >>
2020-05-09 >> 2020-05-10 >> 2 >> YES >>
2020-05-11 >> 2020-05-15 >> 5 >> >>
2020-05-16 >> 2020-05-17 >> 2 >> YES >>
2020-05-18 >> 2020-05-22 >> 5 >> >>
2020-05-23 >> 2020-05-24 >> 2 >> YES >>
2020-05-25 >> 2020-05-29 >> 5 >> >>
2020-05-30 >> 2020-05-31 >> 2 >> YES >>
3rd column: number of days 4th column : prints "YES" if its a weekend