diff --git a/README.md b/README.md index 2fb4d62..59a23c9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ # aoc_template -Template for yearly AoC-Repositories \ No newline at end of file +Template for yearly AoC-Repositories + +# Usage + +- Clone repository (or use as template in gitea) +- Run `pip install -r requirements.txt` +- Update main.py and start_day.py: set YEAR (near the top) to the respective year +- Create a file named ".session" next to your main.py containing the contents of your aoc-session cookie + +On a given day, just call `./start_day.py -d ` + +# Not using PyCharm? + +Just comment out the call() to CHARMS near the end of start_day.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..c02586c --- /dev/null +++ b/main.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import tools.aoc +import argparse +import importlib +import os + +YEAR = 2018 +TIMEIT_NUMBER = 50 + +argument_parser = argparse.ArgumentParser() +argument_parser.add_argument("-d", "--day", help="specify day to process; leave empty for ALL days", type=int) +argument_parser.add_argument("-p", "--part", help="run only part x", choices=[1, 2], type=int) +argument_parser.add_argument("--timeit", help="measure execution time", action="store_true", default=False) +argument_parser.add_argument( + "--timeit-number", + help="build average time over this many executions", + type=int, + default=TIMEIT_NUMBER +) +argument_parser.add_argument("-v", "--verbose", help="show test case outputs", action="store_true", default=False) +flags = argument_parser.parse_args() + +import_day = "" +if flags.day: + import_day = "%02d" % flags.day + +imported = [] +for _, _, files in os.walk(tools.aoc.BASE_PATH): + for f in files: + if f.startswith('day' + import_day) and f.endswith('.py'): + lib_name = f[:-3] + globals()[lib_name] = importlib.import_module(lib_name) + imported.append(lib_name) + + break + +for lib in sorted(imported): + day = int(lib[-2:]) + day_class = getattr(globals()[lib], "Day")(YEAR, day) + day_class.run(flags.part if flags.part else 3, flags.verbose, flags.timeit, flags.timeit_number) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e58fa34 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +shs-tools ~= 0.3 \ No newline at end of file diff --git a/skel_day.py b/skel_day.py new file mode 100644 index 0000000..bf3331b --- /dev/null +++ b/skel_day.py @@ -0,0 +1,24 @@ +from tools.aoc import AOCDay +from typing import Any + + +class Day(AOCDay): + inputs = [ + [ + (None, "input%DAY%"), + ], + [ + (None, "input%DAY%"), + ] + ] + + def part1(self) -> Any: + return "" + + def part2(self) -> Any: + return "" + + +if __name__ == '__main__': + day = Day(%YEAR%, %DAY%) + day.run(verbose=True) diff --git a/start_day.py b/start_day.py new file mode 100644 index 0000000..aa8d394 --- /dev/null +++ b/start_day.py @@ -0,0 +1,51 @@ +#!/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:\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() + +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])