Last active
April 24, 2019 08:32
-
-
Save olliechick/f2bda79dfdc6d21465d6eaa8be847a5a to your computer and use it in GitHub Desktop.
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/python3 | |
from datetime import date, timedelta | |
def represents_int(s): | |
try: | |
int(s) | |
return True | |
except ValueError: | |
return False | |
def represents_date(s): | |
if len(s) != 4 + 2 + 2: | |
return False | |
year = s[0:4] | |
month = s[4:6] | |
day = s[6:8] | |
if represents_int(year) and represents_int(month) and represents_int(day): | |
year = int(year) | |
month = int(month) | |
day = int(day) | |
try: | |
date(year, month, day) | |
return True | |
except ValueError: | |
return False | |
def get_date(s): | |
year = int(s[0:4]) | |
month = int(s[4:6]) | |
day = int(s[6:8]) | |
return date(year, month, day) | |
def main(): | |
first_date_input = input("Enter start date: ") | |
while not represents_date(first_date_input): | |
first_date_input = input("Enter start date (in the format yyyymmdd, e.g. 20191231): ") | |
first_date = get_date(first_date_input) | |
first_number_input = input("Enter first number: ") | |
while not represents_int(first_number_input): | |
first_number_input = input("Enter first number (an integer, e.g. 34): ") | |
first_number = int(first_number_input) | |
end_date_input = input("Enter end date: ") | |
while not represents_date(end_date_input): | |
end_date_input = input("Enter end date (in the format yyyymmdd, e.g. 20191231): ") | |
end_date = get_date(end_date_input) | |
current_date = first_date | |
current_number = first_number | |
print_format = """{} | |
|{} | |
| | |
|{{{{Start date|{}|{}|{}|df=y}}}} | |
|-""" | |
while current_date <= end_date: | |
if current_date.weekday() == 4: # friyay | |
cell_format = 'style="border-bottom: 2px solid black"' | |
else: | |
cell_format = '' | |
if current_date.weekday() < 5: # only print mon-fri | |
print(print_format.format(cell_format, current_number, current_date.year, current_date.month, current_date.day), end='') | |
current_number += 1 | |
current_date += timedelta(days=1) | |
if __name__ == "__main__": | |
main() | |
# Example input: | |
# 20140101 | |
# 1 | |
# 20140201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment