Minimum template for a new AoC year
This commit is contained in:
parent
12a429e3b7
commit
1113d7594c
15
README.md
15
README.md
@ -1,3 +1,16 @@
|
|||||||
# aoc_template
|
# aoc_template
|
||||||
|
|
||||||
Template for yearly AoC-Repositories
|
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 <day_of_month>`
|
||||||
|
|
||||||
|
# Not using PyCharm?
|
||||||
|
|
||||||
|
Just comment out the call() to CHARMS near the end of start_day.py
|
||||||
|
|||||||
41
main.py
Normal file
41
main.py
Normal file
@ -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)
|
||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
shs-tools ~= 0.3
|
||||||
24
skel_day.py
Normal file
24
skel_day.py
Normal file
@ -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)
|
||||||
51
start_day.py
Normal file
51
start_day.py
Normal file
@ -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])
|
||||||
Loading…
Reference in New Issue
Block a user