-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
84 lines (74 loc) · 3.11 KB
/
Copy pathgenerator.py
File metadata and controls
84 lines (74 loc) · 3.11 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import argparse
import os
from datetime import datetime
def create_structure(year, day):
dayDict = {1: "One", 2: "Two", 3: "Three", 4: "Four", 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine", 10: "Ten",
11: "Eleven", 12: "Twelve", 13: "Thirteen", 14: "Fourteen", 15: "Fifteen", 16: "Sixteen", 17: "Seventeen",
18: "Eighteen", 19: "Nineteen", 20: "Twenty", 21: "Twentyone", 22: "Twentytwo", 23: "Twentythree", 24: "Twentyfour", 25: "Twentyfive"}
# Create paths
path = os.path.join(str(year), f"{str(day).zfill(2)}")
if os.path.exists(path):
print(f"Folder {path} already exists. No changes made.")
return
os.makedirs(path, exist_ok=True)
# Create files
input_file = os.path.join(path, "input.txt")
script_file = os.path.join(path, f"Day{dayDict.get(day, f'{day:03d}')}.py")
# Create input.txt
with open(input_file, 'w') as f:
f.write("") # Empty file
# Create DayX.py
with open(script_file, 'w') as f:
f.write(
f'"""\n'
f'\n'
f'"""\n'
f'\n'
f'\n'
f'def inputDocument(document: str) -> list[str]:\n'
f' with open(document, "r") as file:\n'
f' lines = [line.strip() for line in file.readlines() if line.strip()]\n'
f' return lines\n'
f'\n'
f'\n'
f'def formateDocument(document: list[str]):\n'
f' pass\n'
f'\n'
f'\n'
f'def testCase(test: int = 0):\n'
f' if test == 0:\n'
f' return []\n'
f' else:\n'
f' return inputDocument("{year}/{str(day).zfill(2)}/input.txt")\n'
f'\n'
f'\n'
f'def part1(lines) -> int:\n'
f' pass\n'
f'\n'
f'\n'
f'def part2(lines) -> int:\n'
f' pass\n'
f'\n'
f'\n'
f'if __name__ == "__main__":\n'
f' document = testCase(0)\n'
f' formatedDocment = formateDocument(document)\n'
f' print(f"Part 1: {{part1(formatedDocment)}}")\n'
f' print(f"Part 2: {{part2(formatedDocment)}}")\n'
)
print(f"Folder and files created in: {path}")
if __name__ == "__main__":
# Define arguments
parser = argparse.ArgumentParser(description="Creates a folder structure for a year and a day.")
parser.add_argument('-y','--year', type=int, help="Year (e.g., 2024 or 24)")
parser.add_argument('-d','--day', type=int, help="Day (e.g., 1, 2, ... 25)")
# Parse arguments
args = parser.parse_args()
# Use current year and current day if not specified
now = datetime.now()
year = args.year if args.year else now.year
if year < 100: # If year is entered as a two-digit number
year += 2000
day = args.day if args.day else now.day
# Create structure
create_structure(year, day)