#!/usr/bin/env python3 from argparse import ArgumentParser from datetime import datetime from os.path import exists from platform import system from subprocess import call from time import sleep import webbrowser YEAR = 2018 CHARMS = { 'Linux': '/usr/local/bin/charm', 'Windows': r'C:\Program Files\JetBrains\PyCharm 2020.2.4\bin\pycharm64.exe' } arg_parser = ArgumentParser() arg_parser.add_argument("-d", "--day", help="start a specific day (default: today)", type=int) args = arg_parser.parse_args() DAY = args.day or datetime.now().day if YEAR < 2015 or not 1 <= DAY <= 25: print("Invalid year or day for year: %d, day: %d" % (YEAR, DAY)) exit() day_file = "day%02d.py" % DAY if exists(day_file): print(day_file, "already exists. Use that one!") exit() with open("skel_day.py", "r") as IN: with open(day_file, "w") as OUT: while in_line := IN.readline(): OUT.write(in_line.replace("%YEAR%", str(YEAR)).replace("%DAY%", str(DAY))) start = datetime(YEAR, 12, DAY, 6, 0, 0) now = datetime.now() if start > now: time_wait = start - now if time_wait.days > 0: print("Do you really want to wait %d days?" % time_wait.days) exit() for x in range(time_wait.seconds, -1, -1): print("Day starts in %02ds.\r") sleep(1) call([CHARMS[system()], day_file]) webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY)) call(["git", "add", day_file])