-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_handling.py
48 lines (44 loc) · 1.21 KB
/
file_handling.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
import json
import os
from datetime import datetime
from datetime import date
listObj = []
filepath = 'issues_list.json'
new_data = json.loads(os.environ.get('NEW_DATA', '{}'))
print("todays date")
today = date.today()
print(today)
try:
with open(filepath, "r") as json_file:
listObj = json.load(json_file)
except FileNotFoundError:
with open(filepath, "w") as json_file:
listObj.append(new_data)
json.dump(listObj, json_file, indent=4)
else:
print(len(listObj))
listObjwrite = []
for x in range(len(listObj)):
print("================")
print(x)
d = listObj[x]
print(d)
print(type(d))
if d['Skip shutdown end date'] == "_No response_":
d['Skip shutdown end date'] = today.strftime('%d-%m-%Y')
print(d)
listObjwrite.append(d)
print(listObjwrite)
else:
end_date = datetime.strptime(d['Skip shutdown end date'], '%d-%m-%Y').date()
print( end_date)
print(type(end_date))
if today < end_date:
listObjwrite.append(d)
print(listObjwrite)
if new_data:
listObjwrite.append(new_data)
print("before write")
print(listObjwrite)
with open(filepath, "w") as json_file:
json.dump(listObjwrite, json_file, indent=4)