First working copy using sqlite3

This commit is contained in:
FrederikBaerentsen 2024-04-16 21:43:30 +02:00
parent 08a90db2f5
commit cbe6f16659
3 changed files with 11 additions and 18 deletions

12
app.py
View File

@ -206,9 +206,17 @@ def index():
conn = sqlite3.connect('app.db')
cursor = conn.cursor()
cursor.execute('SELECT * from sets;')
set_list = cursor.fetchall()
results = cursor.fetchall()
set_list = [list(i) for i in results]
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()
conn.close()
@ -257,7 +265,7 @@ def inventory(tmp,u_id):
cursor = conn.cursor()
# 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
cursor.execute('''SELECT quantity FROM missing
WHERE set_num = ? AND

16
lego.py
View File

@ -34,9 +34,6 @@ with open('api','r') as f:
rb = rebrick.init(api_key)
# if Path(set_path).is_dir():
# print('Set exists, exitting')
# logging.error('Set exists!')
@ -94,11 +91,9 @@ for i in response["results"]:
if i['element_id'] == None:
if not Path("./static/parts/p_"+i["part"]["part_id"]+".jpg").is_file():
res = requests.get(i["part"]["part_img_url"], stream = True)
if res.status_code == 200:
with open("./static/parts/p_"+i["part"]["part_id"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print(i["part"]["part_id"])
else:
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
res = requests.get(i["part"]["part_img_url"], stream = True)
@ -106,25 +101,21 @@ for i in response["results"]:
if res.status_code == 200:
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print(i["part"]["part_id"])
if not Path("./static/parts/"+i["element_id"]+".jpg").is_file():
res = requests.get(i["part"]["part_img_url"], stream = True)
if res.status_code == 200:
with open("./static/parts/"+i["element_id"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print(i["part"]["part_id"])
except Exception as e:
print(e)
logging.error(set_num + ": " + str(e))
# read info file with missing pieces
if Path("./info/"+set_num + ".json").is_file():
with open("./info/" + set_num + ".json") as f:
data = json.load(f)
print(data)
else:
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)
logging.error('set_img_url: ' + set_num)
response = json.loads(rebrick.lego.get_minifig_elements(x["set_num"]).read())
for i in response["results"]:
@ -167,7 +157,6 @@ for x in response["results"]:
}
fig["parts"].append(part)
try:
if i['element_id'] == None:
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:
with open("./static/figs/p_"+i["part"]["part_num"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print('image saved')
else:
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
res = requests.get(i["part"]["part_img_url"], stream = True)
@ -184,14 +172,12 @@ for x in response["results"]:
if res.status_code == 200:
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print('image saved')
if not Path("./static/figs/"+i["part"]["part_num"]+".jpg").is_file():
res = requests.get(i["part"]["part_img_url"], stream = True)
if res.status_code == 200:
with open("./static/figs/"+i["part"]["part_num"]+".jpg",'wb') as f:
shutil.copyfileobj(res.raw, f)
print('image saved')
except Exception as e:
print(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)
####
print('Done!')
print('Done!')

View File

@ -119,7 +119,6 @@ body {
<option value="">Select Theme</option>
</select>
<!-- Add more buttons for other text values if needed -->
</div>
<div class="grid-container" id="gridContainer">