From cbe6f166595914201bbb5896f6bb70df76c2c5c0 Mon Sep 17 00:00:00 2001
From: FrederikBaerentsen <frederik+gitea@baerentsen.net>
Date: Tue, 16 Apr 2024 21:43:30 +0200
Subject: [PATCH] First working copy using sqlite3

---
 app.py                   | 12 ++++++++++--
 lego.py                  | 16 +---------------
 templates/frontpage.html |  1 -
 3 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/app.py b/app.py
index a973058..617e1f2 100644
--- a/app.py
+++ b/app.py
@@ -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 
diff --git a/lego.py b/lego.py
index f738aa2..0516f2e 100644
--- a/lego.py
+++ b/lego.py
@@ -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!')
\ No newline at end of file
+print('Done!')
diff --git a/templates/frontpage.html b/templates/frontpage.html
index 1d4b450..e8f658a 100644
--- a/templates/frontpage.html
+++ b/templates/frontpage.html
@@ -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">