-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_new_task.py
63 lines (45 loc) · 1.78 KB
/
start_new_task.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
import os
from datetime import date
import webbrowser
def create_dictionary(year: int):
year_as_string = str(year)
if not os.path.exists(year_as_string):
os.mkdir(year_as_string)
def create_files(year: int, day: int):
day_with_zero = str(day).zfill(2)
file_input_name = f'input.{day_with_zero}.txt'
with open('.new_task.template.py') as in_file:
with open(os.path.join(str(year), f'{year}_{day_with_zero}.py'), 'w') as out_file:
out_file.writelines(in_file.read().format(
day=day,
year=year,
day_with_zero=day_with_zero,
file_input_name=file_input_name
))
with open(file_input_name, 'w') as file:
file.writelines('')
def open_tabs(year: int, day: int):
webbrowser.open(f'https://adventofcode.com/{year}/day/{day}/input')
webbrowser.open(f'https://adventofcode.com/{year}/day/{day}')
def is_solution_for_day_exist(year, day):
day_with_zero = str(day).zfill(2)
file_name = f'{year}_{day_with_zero}.py'
return os.path.exists(os.path.join(str(year), file_name))
def find_first_missing(today):
for year in range(2015, today.year + 1):
directory_name = str(year)
if not os.path.exists(directory_name):
return year, 1
for day in range(1, 26):
if not is_solution_for_day_exist(year, day):
return year, day
def for_which_date_create(input_date):
if input_date.month == 12 and input_date.day <= 25 and not is_solution_for_day_exist(input_date.year, input_date.day):
return today.year, today.day
else:
return find_first_missing(today)
today = date.today()
year, day = for_which_date_create(today)
create_dictionary(year)
create_files(year, day)
open_tabs(year, day)