-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep.py
44 lines (37 loc) · 2.14 KB
/
prep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ------------------------------------------------------------------------------
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# ------------------------------------------------------------------------------
"""
Script to prep the directory structure for a specific day of AoC.
"""
if __name__ == "__main__":
import argparse
from datetime import date
from os import mkdir
from os.path import isdir, isfile
# Get the template code
with open("template.py") as f:
template = f.read()
# Create the argument parser
parser = argparse.ArgumentParser(description='Create template AoC folders and files')
parser.add_argument('day', type=int, choices=range(1, 26), help='which day to create', metavar='DAY')
parser.add_argument('-y', '--year', type=int, default=date.today().year,
help='which year to create (default: current year)', metavar='YEAR')
# Parse the provided arguments
args = parser.parse_args()
if not isdir("AoC_{}".format(args.year)): # Create the year folder if needed
mkdir("AoC_{}".format(args.year))
if not isdir("AoC_{}/Day_{:02}".format(args.year, args.day)): # Create the day folder if needed
mkdir("AoC_{}/Day_{:02}".format(args.year, args.day))
if not isdir("AoC_{}/Day_{:02}/data".format(args.year, args.day)): # Create the data folder if needed
mkdir("AoC_{}/Day_{:02}/data".format(args.year, args.day))
if not isfile("AoC_{}/Day_{:02}/part1.py".format(args.year, args.day)): # Create the part 1 file if needed
with open("AoC_{}/Day_{:02}/part1.py".format(args.year, args.day), "w") as f:
f.write(template)
if not isfile("AoC_{}/Day_{:02}/part2.py".format(args.year, args.day)): # Create the part 2 file if needed
with open("AoC_{}/Day_{:02}/part2.py".format(args.year, args.day), "w") as f:
f.write(template)
# TODO: Automatically retrieve and parse test inputs
# TODO: Automatically retrieve and store problem description as README.md