misc-tools/python/quarantine-day-counter

47 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-12-17 11:43:54 +00:00
#!/usr/bin/env python3
"""
Calculates the number of actual days since everyone
went into hiding (quarantine).
"""
import argparse
import datetime
import dateutil.parser
try:
import color
except:
print("Unable to import the color library. No colors for you.")
2020-12-17 11:43:54 +00:00
quarantine_start_date = "13 Mar 2020"
def parse_args():
argp = argparse.ArgumentParser()
argp.add_argument(
'-s', '--start-date',
default=quarantine_start_date,
help="Different start date than the original (%(default)s)"
)
2020-12-17 11:43:54 +00:00
return argp.parse_args()
def quarantine_days(quarantine_start_date=quarantine_start_date):
q_count = datetime.datetime.now() - dateutil.parser.parse(quarantine_start_date)
return q_count.days
if __name__ == "__main__":
args = parse_args()
try:
start_date_message = f"\nQuarantine Start Date: {color.yellow(args.start_date)}"
quarantine_days_message = f"Quarantine Days: {color.red(quarantine_days(args.start_date))}"
except NameError:
start_date_message = f"\nQuarantine Start Date: {args.start_date}"
quarantine_days_message = f"Quarantine Days: {quarantine_days(args.start_date)}"
print(start_date_message)
print(quarantine_days_message)
2020-12-17 11:43:54 +00:00