#!/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 from tools.tools import human_readable_time_from_delta import webbrowser YEAR = 2016 CHARMS = { 'Linux': '/usr/local/bin/charm', 'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd' } 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() 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() while time_wait.seconds > 0: print("Day %d starts in %s.\r" % (DAY, human_readable_time_from_delta(time_wait))) if time_wait.seconds > 70: wait = min(1, time_wait.seconds // 3600) * 3600 + min(1, time_wait.seconds // 60) * 60 sleep(wait) else: sleep(1) time_wait = start - datetime.now() 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))) call(["git", "add", day_file]) webbrowser.open("https://adventofcode.com/%d/day/%d" % (YEAR, DAY)) call([CHARMS[system()], day_file])