move file load to new file, add csv data maker.
This commit is contained in:
parent
82b958122b
commit
0af780f1ac
55
file_load.py
Normal file
55
file_load.py
Normal file
@ -0,0 +1,55 @@
|
||||
from ItemRelate import main as relate
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
|
||||
def batch():
|
||||
scales = os.listdir("Scales")
|
||||
items={}
|
||||
for i in scales:
|
||||
with open("Scales/"+i,"r") as scale:
|
||||
tmp = json.load(scale)
|
||||
for i in tmp["item"]:
|
||||
items[i]=tmp["item"][i]
|
||||
# print(items)
|
||||
return items
|
||||
|
||||
def old_type(str):
|
||||
with open(str,"r") as file:
|
||||
scale=json.load(file)
|
||||
new={"item":{}}
|
||||
for i in scale:
|
||||
new["item"][i["name"]]=i["label"]
|
||||
# print(i["name"],i["label"])
|
||||
with open(str,"w") as file:
|
||||
file.write(json.dumps(new))
|
||||
|
||||
def data():
|
||||
s=""
|
||||
|
||||
item = batch()
|
||||
for i in item:
|
||||
s+=i+','
|
||||
s=s[:-1]+'\n'
|
||||
|
||||
for i in range(0,1000):
|
||||
s += str(random.randint(0,4))
|
||||
for j in range(1,20):
|
||||
s += ',' + str(random.randint(0,4))
|
||||
s+='\n'
|
||||
|
||||
with open("Temp/data.csv","w") as data:
|
||||
data.write(s)
|
||||
|
||||
|
||||
def main(force:bool = False):
|
||||
if force or os.path.getsize("Temp/items.json") == 0:
|
||||
que=relate(batch())
|
||||
with open("Temp/items.json","w") as items:
|
||||
items.write(json.dumps(que))
|
||||
else:
|
||||
with open("Temp/items.json","r") as items:
|
||||
que = json.load(items)
|
||||
data()
|
||||
return que
|
33
main.py
33
main.py
@ -1,37 +1,10 @@
|
||||
from ItemRelate import main as relate
|
||||
from file_load import main as init
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
def batch():
|
||||
scales = os.listdir("Scales")
|
||||
items={}
|
||||
for i in scales:
|
||||
with open("Scales/"+i,"r") as scale:
|
||||
tmp = json.load(scale)
|
||||
for i in tmp["item"]:
|
||||
items[i]=tmp["item"][i]
|
||||
# print(items)
|
||||
return items
|
||||
|
||||
def old_type(str):
|
||||
with open(str,"r") as file:
|
||||
scale=json.load(file)
|
||||
new={"item":{}}
|
||||
for i in scale:
|
||||
new["item"][i["name"]]=i["label"]
|
||||
# print(i["name"],i["label"])
|
||||
with open(str,"w") as file:
|
||||
file.write(json.dumps(new))
|
||||
|
||||
# old_type("Scales/ceE.json")
|
||||
|
||||
if os.path.getsize("Temp/items.json") == 0:
|
||||
que=relate(batch())
|
||||
with open("Temp/items.json","w") as items:
|
||||
items.write(json.dumps(que))
|
||||
else:
|
||||
with open("Temp/items.json","r") as items:
|
||||
que = json.load(items)
|
||||
que = init()
|
||||
|
||||
for i in que:
|
||||
print(i)
|
||||
|
Loading…
Reference in New Issue
Block a user