-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.py
67 lines (50 loc) · 1.83 KB
/
bootstrap.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Create skeleton solution script for given day."""
import argparse
import os
from os.path import dirname, realpath, join
from shutil import copyfile
from aocd import get_data
def parse_args():
parser = argparse.ArgumentParser(description="Bootstrap")
parser.add_argument("-y", "--year", required=True, type=int, help="year")
parser.add_argument("-d", "--day", required=True, type=int, help="day")
parser.add_argument(
"-cpp",
"--cpp",
action="store_true",
help="Bootstrap C++ template solution",
)
return parser.parse_args()
def download_input(year, day, dst_input_path):
try:
data = get_data(year=year, day=day)
print(f"Fetched input year-{year}, day-{day}")
except Exception:
print("Failed to fetch input, creating empty input file")
data = ""
with open(dst_input_path, "w") as f:
f.write(data)
def bootstrap_solution(year, day, cpp):
target_dir = join(f"{year}", f"day{day}")
os.makedirs(target_dir, exist_ok=True)
dst_py = join(target_dir, "solve.py")
dst_cpp = join(target_dir, "solve.cpp")
if not os.path.exists(dst_py):
src_py = join(dirname(realpath(__file__)), "template.py")
copyfile(src_py, dst_py)
print(f"Created python skeleton for year-{year}, day-{day}")
if not os.path.exists(dst_cpp) and cpp:
src_cpp = join(dirname(realpath(__file__)), "template.cpp")
copyfile(src_cpp, dst_cpp)
print(f"Created c++ skeleton for year-{year}, day-{day}")
dst_input_path = join(target_dir, "input.txt")
if not os.path.exists(dst_input_path):
download_input(year, day, dst_input_path)
def main():
args = parse_args()
day = args.day
year = args.year
cpp = args.cpp
bootstrap_solution(year, day, cpp)
if __name__ == "__main__":
main()