Created
March 15, 2020 18:59
-
-
Save xai/a5ba77f00de6288114a6997adc0475c3 to your computer and use it in GitHub Desktop.
This file contains 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 python3 | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2020 Olaf Lessenich <xai@linux.com> | |
# | |
# Distributed under terms of the MIT license. | |
from datetime import timedelta, datetime | |
import argparse | |
import errno | |
import os | |
def daterange(start_date, end_date): | |
for n in range(int((end_date - start_date).days)): | |
yield start_date + timedelta(n) | |
def main(start, end, workload, holidays, vacation, all): | |
print("start: " + start) | |
print("end: " + end) | |
start_date = datetime.strptime(start, "%Y-%m-%d") | |
end_date = datetime.strptime(end, "%Y-%m-%d") | |
months = dict() | |
for d in daterange(start_date, end_date): | |
m = d.strftime("%Y-%m") | |
iso = d.strftime("%Y-%m-%d") | |
if m not in months: | |
months[m] = 0 | |
is_weekend = d.weekday() >= 5 | |
is_vacation = False | |
is_holiday = False | |
with open(holidays, 'r') as h, open(vacation, 'r') as v: | |
is_holiday = iso in h.read() | |
is_vacation = iso in v.read() | |
if all or not (is_weekend or is_holiday or is_vacation): | |
print(d.strftime("%Y-%m-%d (%A)"), end='') | |
if is_weekend: | |
pass | |
elif is_holiday: | |
print(" holiday", end='') | |
elif is_vacation: | |
print(" vacation", end='') | |
else: | |
months[m] += 1 | |
print() | |
print() | |
days = 0 | |
for month in months: | |
days += months[month] | |
print("%s: %d days (%.2f hours)" % (month, months[month], workload * | |
months[month])) | |
print() | |
print("Total: %d days (%.2f hours)" % (days, workload * days)) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("-a", | |
"--all", | |
help="show all days", | |
action="store_true") | |
parser.add_argument("-w", | |
"--workload", | |
help="number of hours per day", | |
required=True, | |
type=float) | |
parser.add_argument("--holidays", | |
help="file with holidays", | |
type=str, | |
default="holidays-at.txt") | |
parser.add_argument("--vacation", | |
help="file with vacations", | |
type=str, | |
default="vacation.txt") | |
parser.add_argument("start", type=str) | |
parser.add_argument("end", type=str) | |
args = parser.parse_args() | |
if args.holidays and not os.path.exists(args.holidays): | |
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), | |
args.holidays) | |
if args.vacation and not os.path.exists(args.vacation): | |
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), | |
args.vacation) | |
main(args.start, args.end, args.workload, args.holidays, args.vacation, | |
args.all) |
This file contains 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
2019-01-01 | |
2019-01-06 | |
2019-04-21 | |
2019-04-22 | |
2019-05-01 | |
2019-05-30 | |
2019-06-09 | |
2019-06-10 | |
2019-06-20 | |
2019-08-15 | |
2019-10-26 | |
2019-11-01 | |
2019-12-08 | |
2019-12-24 | |
2019-12-25 | |
2019-12-26 | |
2019-12-31 | |
2020-01-01 | |
2020-01-06 | |
2020-04-12 | |
2020-04-13 | |
2020-05-01 | |
2020-05-21 | |
2020-05-31 | |
2020-06-01 | |
2020-06-11 | |
2020-08-15 | |
2020-10-26 | |
2020-11-01 | |
2020-12-08 | |
2020-12-24 | |
2020-12-25 | |
2020-12-26 | |
2020-12-31 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment