觉醒时刻
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
juexingshike/tools/goodid.py

37 lines
809 B

1 week ago
# -*- coding:utf-8 -*-
# python 3.10
import json,shutil,os
# 当前目录
curPath = os.getcwd()
imgpath = curPath + '/img/'
jsonpath = curPath + '/goods.json'
# 读取json文件
with open(jsonpath, 'r', encoding='utf-8') as file:
data = json.load(file)
goodid = 0
def traverse_json(data):
if isinstance(data, dict):
for key, value in data.items():
print(key, ':')
traverse_json(value)
elif isinstance(data, list):
for item in data:
traverse_json(item)
else:
print(data)
if type(data) == int:
global goodid
goodid = data
else:
if os.path.exists(imgpath+data+'.png'):
os.rename(imgpath+data+'.png', imgpath+str(goodid)+'.png')
traverse_json(data)