-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeJSON.py
51 lines (49 loc) ยท 1.62 KB
/
changeJSON.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
import json
import os
import datetime
import pytz
import shutil
timeformat = datetime.datetime.now(pytz.timezone('Asia/Seoul'))
timeformat = f"{timeformat.strftime('%Y-%m-%d')}"
#IMG Archiving
try:
path_dir = "./archive/"
file_list = os.listdir(path_dir)
print(file_list)
if timeformat in file_list:
arc = path_dir+ timeformat #์์นด์ด๋ธ๋๋ ๋๋ ํ ๋ฆฌ ์ฃผ์
cnt = len(os.listdir(arc))
if cnt == 0:
shutil.copy2("./build/images/1.png", arc + "/1.png")
else:
shutil.copy2("./build/images/1.png", arc + "/"+ str(cnt+1) +".png")
else:
os.mkdir(path_dir + timeformat)
shutil.copy2("./build/images/1.png", path_dir + timeformat + "/1.png")
except:
print("Failed")
#METADATA Archiving
with open("./build/json/1.json", "r") as json_file:
json_data = json.load(json_file)
json_data.pop('edition')
json_data.pop('compiler')
with open("./build/json/1.json", 'w') as outfile:
json.dump(json_data, outfile, indent=4)
try:
path_dir = "./metadata/"
file_list = os.listdir(path_dir)
print(file_list)
if timeformat in file_list:
arc = path_dir+ timeformat #์์นด์ด๋ธ๋๋ ๋๋ ํ ๋ฆฌ ์ฃผ์
cnt = len(os.listdir(arc))
if cnt == 0:
shutil.copy2("./build/json/1.json", arc + "/1.json")
else:
shutil.copy2("./build/json/1.json", arc + "/"+ str(cnt+1) +".json")
else:
os.mkdir(path_dir + timeformat)
shutil.copy2("./build/json/1.json", path_dir + timeformat + "/1.json")
except:
print("Failed")
#reference
#https://abluesnake.tistory.com/107