Better template for python

This commit is contained in:
hedy 2022-12-22 16:41:44 +08:00
parent d4dc30e699
commit b721bc6a71
Signed by: hedy
GPG Key ID: B51B5A8D1B176372
1 changed files with 32 additions and 7 deletions

View File

@ -1,12 +1,37 @@
from aocd import submit
with open("input.txt") as f:
# https://adventofcode.com/YEAR/day/DAY
#
## USAGE ##
# Run with 'input.txt' and submit with aocd:
# python3 python.py
# Run with 'test.txt' and don't submit:
# python3 python.py test.txt
# Run with stdin and don't submit:
# cat myinput | python3 python.py -
# aoc d -y YEAR -d DAY -oi /dev/stdout | python3 python.py -
# aocd DAY YEAR | python3 python.py -
if __name__ == '__main__':
submit( , "a", DAY, YEAR)
import sys
inputfn = sys.argv[1] if len(sys.argv) > 1 else "input.txt"
submit( , "b", DAY, YEAR)
from aocd import submit
with open(0 if inputfn == '-' else inputfn) as f:
lines = f.read().splitlines()
# part 1
print()
if inputfn == "input.txt":
submit(, "a", day=DAY, year=YEAR)
# part 2
print()
if inputfn == "input.txt":
submit(, "b", day=DAY, year=YEAR)