Created
July 3, 2017 04:23
-
-
Save manashmandal/e45780dea2d98a380b7d0231afb72864 to your computer and use it in GitHub Desktop.
Generate dates and weekdays excluding weekends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# simply do the following to generate dates for month 12 | |
# curl -s apl-days.py | python - 12 2017 | |
from datetime import date | |
from calendar import monthrange | |
from sys import argv | |
# check if any argument is provided | |
try: | |
MONTH = int(argv[1]) | |
YEAR = int(argv[2]) | |
# if not, generate dates for current month | |
except: | |
MONTH = date.today().month | |
YEAR = date.today().year | |
WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] | |
WEEKENDS = ["Friday", "Saturday"] | |
for day in xrange(1, monthrange(YEAR, MONTH)[1] + 1): | |
someday = date(YEAR, MONTH, day) | |
weekday = WEEKDAYS[someday.weekday()] | |
if weekday not in WEEKENDS: print someday, '(' + weekday + ')' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment