Skip to content

Commit b23f512

Browse files
committed
Use current year in license during starter code generation from templates
1 parent 4e643a7 commit b23f512

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

gen_day.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323

24+
import datetime
2425
import os
2526
import sys
2627

@@ -48,9 +49,14 @@ def generate_code_for_day(day):
4849

4950
with open(os.path.join("templates", "license.template")) as license_f:
5051
var_map = {
51-
"license": license_f.read(),
52+
"advent_year": "2020",
53+
"date_year": str(datetime.datetime.now().year),
5254
"day": str(day)
5355
}
56+
57+
license_template = license_f.read()
58+
var_map["license"] = substitute_vars(license_template, var_map)
59+
5460
gen_file_from_template(os.path.join("templates", "day.template"), day_file_path, var_map)
5561
gen_file_from_template(os.path.join("templates", "test.template"), test_file_path, var_map)
5662

templates/license.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22
#
3-
# Copyright (c) 2020 Andrew Krepps
3+
# Copyright (c) ${date_year} Andrew Krepps
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal

templates/test.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ ${license}
33

44
import unittest
55

6-
from advent2020.day${day} import get_part1_answer
7-
from advent2020.day${day} import get_part2_answer
8-
from advent2020.util import get_input_data_lines
6+
from advent${advent_year}.day${day} import get_part1_answer
7+
from advent${advent_year}.day${day} import get_part2_answer
8+
from advent${advent_year}.util import get_input_data_lines
99

1010

1111
data = """

0 commit comments

Comments
 (0)