-
Notifications
You must be signed in to change notification settings - Fork 0
/
year_case_finder.pyw
84 lines (73 loc) · 2.21 KB
/
year_case_finder.pyw
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 os, datetime
def year_case_finder(year, month, day):
laiks = datetime.datetime(year, month, day).strftime('%Y%m%d')
case = []
for filename in os.listdir('.'):
if filename.endswith(".sav"):
db = []
db.append(filename)
for i in db:
if laiks == db[0][:8]:
case.append(filename)
else:
continue
if not case:
return False
else:
return case
def closest_case_finder(year, month, day):
laiks = datetime.datetime(year, month, day).strftime('%Y%m')
case = []
for filename in os.listdir('.'):
if filename.endswith(".sav"):
db = []
db.append(filename)
for i in db:
if laiks == db[0][:6]:
case.append(filename)
else:
continue
if not case:
return False
else:
return case
def day_of_week(year, month, day):
diena = int(datetime.datetime(year, month, day).strftime('%w'))
if diena == 0 or diena == 6:
return 0
else:
return 1
def get_case(c_case, i):
get_case = []
if i == 0:
for f in range(len(c_case)):
case = c_case[f]
s = int((datetime.datetime.strptime(c_case[f][:8], "%Y%m%d")).strftime('%w'))
if s == 0 or s == 6:
get_case.append(case)
else:
continue
else:
for f in range(len(c_case)):
case = c_case[f]
s = int((datetime.datetime.strptime(c_case[f][:8], "%Y%m%d")).strftime('%w'))
if 1 <= s <= 5:
get_case.append(case)
else:
continue
return get_case
year = input("Year: ")
month = input("Month: ")
day = input("Day: ")
case = year_case_finder(year, month, day)
if case == False:
c_case = closest_case_finder(year, month, day)
if c_case == False:
print('No case exist!')
else:
i = day_of_week(year, month, day)
case = get_case(c_case, i)
print(case)
else:
print('Exact case found, job done!')
print(case)