-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_script.sh
More file actions
45 lines (40 loc) · 1.55 KB
/
day_script.sh
File metadata and controls
45 lines (40 loc) · 1.55 KB
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
#!/usr/bin/env sh
folder_name="Day $1"
if [ "$1" == "" ]
then
echo "Parameter missing. Please add valid number"
elif ! [[ $1 =~ ^-?[0-9]{1,3}$ ]]
then
echo "Provide valid day number"
elif [ -d "$folder_name" ]
then
echo "Directory /path/to/dir exists."
else
mkdir "$folder_name"
# create functions file
{
printf "from helpers.helpers import read_file\n\n\n"
printf "def section_1_function(file_name):\n"
printf " file = read_file(file_name)\n"
printf " return file\n\n\n"
printf "def section_2_function(file_name):\n"
printf " file = read_file(file_name)\n"
printf " return file\n"
}>>"$folder_name/day_$1_functions.py"
# create main file
{
printf "from day_%s_functions import section_1_function, section_2_function\n" "$1"
printf "from helpers.helpers import output_test_result, output_result\n\n"
echo "if __name__ == \"__main__\":"
printf " # Part 1\n"
printf " print(output_test_result('result' == section_1_function(\"test_input.txt\"), %s, 1))\n" "$1"
printf " print(output_result(section_1_function(\"input.txt\"), %s, 1))\n\n" "$1"
printf " # Part 2\n"
printf " print(output_test_result('result' == section_2_function(\"test_input.txt\"), %s, 2))\n" "$1"
printf " print(output_result(section_2_function(\"input.txt\"), %s, 2))\n" "$1"
}>>"$folder_name/day$1.py"
echo "">"$folder_name/test_input.txt"
echo "">"$folder_name/input.txt"
git add "$folder_name/*"
printf "\n\n[Day %s: ](https://adventofcode.com/2020/day/%s)" "$1" "$1" >> "README.md"
fi