First working copy using sqlite3
This commit is contained in:
parent
08a90db2f5
commit
cbe6f16659
12
app.py
12
app.py
@ -206,9 +206,17 @@ def index():
|
|||||||
conn = sqlite3.connect('app.db')
|
conn = sqlite3.connect('app.db')
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute('SELECT * from sets;')
|
cursor.execute('SELECT * from sets;')
|
||||||
set_list = cursor.fetchall()
|
|
||||||
|
results = cursor.fetchall()
|
||||||
|
set_list = [list(i) for i in results]
|
||||||
|
|
||||||
print(set_list)
|
print(set_list)
|
||||||
|
for i in set_list:
|
||||||
|
try:
|
||||||
|
i[3] = theme_file[theme_file[:, 0] == str(i[3])][0][1]
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -257,7 +265,7 @@ def inventory(tmp,u_id):
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# If quantity is not empty
|
# If quantity is not empty
|
||||||
if missing is not '' and missing is not '0':
|
if missing != '' and missing != '0':
|
||||||
#Check if there's an existing entry
|
#Check if there's an existing entry
|
||||||
cursor.execute('''SELECT quantity FROM missing
|
cursor.execute('''SELECT quantity FROM missing
|
||||||
WHERE set_num = ? AND
|
WHERE set_num = ? AND
|
||||||
|
16
lego.py
16
lego.py
@ -34,9 +34,6 @@ with open('api','r') as f:
|
|||||||
|
|
||||||
rb = rebrick.init(api_key)
|
rb = rebrick.init(api_key)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# if Path(set_path).is_dir():
|
# if Path(set_path).is_dir():
|
||||||
# print('Set exists, exitting')
|
# print('Set exists, exitting')
|
||||||
# logging.error('Set exists!')
|
# logging.error('Set exists!')
|
||||||
@ -94,11 +91,9 @@ for i in response["results"]:
|
|||||||
if i['element_id'] == None:
|
if i['element_id'] == None:
|
||||||
if not Path("./static/parts/p_"+i["part"]["part_id"]+".jpg").is_file():
|
if not Path("./static/parts/p_"+i["part"]["part_id"]+".jpg").is_file():
|
||||||
res = requests.get(i["part"]["part_img_url"], stream = True)
|
res = requests.get(i["part"]["part_img_url"], stream = True)
|
||||||
|
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/parts/p_"+i["part"]["part_id"]+".jpg",'wb') as f:
|
with open("./static/parts/p_"+i["part"]["part_id"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print(i["part"]["part_id"])
|
|
||||||
else:
|
else:
|
||||||
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
|
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
|
||||||
res = requests.get(i["part"]["part_img_url"], stream = True)
|
res = requests.get(i["part"]["part_img_url"], stream = True)
|
||||||
@ -106,25 +101,21 @@ for i in response["results"]:
|
|||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
|
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print(i["part"]["part_id"])
|
|
||||||
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
|
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
|
||||||
res = requests.get(i["part"]["part_img_url"], stream = True)
|
res = requests.get(i["part"]["part_img_url"], stream = True)
|
||||||
|
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
|
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print(i["part"]["part_id"])
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
logging.error(set_num + ": " + str(e))
|
logging.error(set_num + ": " + str(e))
|
||||||
|
|
||||||
# read info file with missing pieces
|
# read info file with missing pieces
|
||||||
|
|
||||||
|
|
||||||
if Path("./info/"+set_num + ".json").is_file():
|
if Path("./info/"+set_num + ".json").is_file():
|
||||||
with open("./info/" + set_num + ".json") as f:
|
with open("./info/" + set_num + ".json") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
print(data)
|
|
||||||
else:
|
else:
|
||||||
shutil.copy("set_template.json", "./info/"+set_num+".json")
|
shutil.copy("set_template.json", "./info/"+set_num+".json")
|
||||||
|
|
||||||
@ -153,7 +144,6 @@ for x in response["results"]:
|
|||||||
print('Image Couldn\'t be retrieved for set ' + set_num)
|
print('Image Couldn\'t be retrieved for set ' + set_num)
|
||||||
logging.error('set_img_url: ' + set_num)
|
logging.error('set_img_url: ' + set_num)
|
||||||
|
|
||||||
|
|
||||||
response = json.loads(rebrick.lego.get_minifig_elements(x["set_num"]).read())
|
response = json.loads(rebrick.lego.get_minifig_elements(x["set_num"]).read())
|
||||||
|
|
||||||
for i in response["results"]:
|
for i in response["results"]:
|
||||||
@ -167,7 +157,6 @@ for x in response["results"]:
|
|||||||
}
|
}
|
||||||
fig["parts"].append(part)
|
fig["parts"].append(part)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if i['element_id'] == None:
|
if i['element_id'] == None:
|
||||||
if not Path("./static/figs/p_"+i["part"]["part_num"]+".jpg").is_file():
|
if not Path("./static/figs/p_"+i["part"]["part_num"]+".jpg").is_file():
|
||||||
@ -176,7 +165,6 @@ for x in response["results"]:
|
|||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/figs/p_"+i["part"]["part_num"]+".jpg",'wb') as f:
|
with open("./static/figs/p_"+i["part"]["part_num"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print('image saved')
|
|
||||||
else:
|
else:
|
||||||
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
|
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
|
||||||
res = requests.get(i["part"]["part_img_url"], stream = True)
|
res = requests.get(i["part"]["part_img_url"], stream = True)
|
||||||
@ -184,14 +172,12 @@ for x in response["results"]:
|
|||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
|
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print('image saved')
|
|
||||||
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
|
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
|
||||||
res = requests.get(i["part"]["part_img_url"], stream = True)
|
res = requests.get(i["part"]["part_img_url"], stream = True)
|
||||||
|
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
|
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
|
||||||
shutil.copyfileobj(res.raw, f)
|
shutil.copyfileobj(res.raw, f)
|
||||||
print('image saved')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
logging.error(set_num + ": " + str(e))
|
logging.error(set_num + ": " + str(e))
|
||||||
@ -204,4 +190,4 @@ with open(set_path+'minifigs.json', 'w', encoding='utf-8') as f:
|
|||||||
json.dump(figures, f, ensure_ascii=False, indent=4)
|
json.dump(figures, f, ensure_ascii=False, indent=4)
|
||||||
####
|
####
|
||||||
|
|
||||||
print('Done!')
|
print('Done!')
|
||||||
|
@ -119,7 +119,6 @@ body {
|
|||||||
<option value="">Select Theme</option>
|
<option value="">Select Theme</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<!-- Add more buttons for other text values if needed -->
|
<!-- Add more buttons for other text values if needed -->
|
||||||
</div>
|
</div>
|
||||||
<div class="grid-container" id="gridContainer">
|
<div class="grid-container" id="gridContainer">
|
||||||
|
Loading…
Reference in New Issue
Block a user