Basic wishlist feature
This commit is contained in:
parent
baf5841502
commit
608681f4bc
76
app.py
76
app.py
@ -494,46 +494,56 @@ def wishlist():
|
||||
input_value = 'None'
|
||||
|
||||
if request.method == 'POST':
|
||||
input_value = request.form.get('inputField')
|
||||
print(input_value)
|
||||
|
||||
if 'create_submit' in request.form:
|
||||
input_value = request.form.get('inputField')
|
||||
print(input_value)
|
||||
|
||||
|
||||
input_value = input_value.replace(" ","")
|
||||
if '-' not in input_value:
|
||||
input_value = input_value + '-1'
|
||||
input_value = input_value.replace(" ","")
|
||||
if '-' not in input_value:
|
||||
input_value = input_value + '-1'
|
||||
|
||||
total_set_file = np.genfromtxt("sets.csv",delimiter=",",dtype="str",usecols=(0))
|
||||
if input_value not in total_set_file:
|
||||
print('ERROR: ' + input_value)
|
||||
#return render_template('wishlist.html',error=input_value)
|
||||
total_set_file = np.genfromtxt("sets.csv",delimiter=",",dtype="str",usecols=(0))
|
||||
if input_value not in total_set_file:
|
||||
print('ERROR: ' + input_value)
|
||||
#return render_template('wishlist.html',error=input_value)
|
||||
|
||||
else:
|
||||
set_num = input_value
|
||||
|
||||
input_value = 'None'
|
||||
else:
|
||||
set_num = input_value
|
||||
|
||||
input_value = 'None'
|
||||
conn = sqlite3.connect('app.db')
|
||||
cursor = conn.cursor()
|
||||
rb = rebrick.init(os.getenv("REBRICKABLE_API_KEY"))
|
||||
response = json.loads(rebrick.lego.get_set(set_num).read())
|
||||
cursor.execute('''INSERT INTO wishlist (
|
||||
set_num,
|
||||
name,
|
||||
year,
|
||||
theme_id,
|
||||
num_parts,
|
||||
set_img_url,
|
||||
set_url,
|
||||
last_modified_dt
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ''', (response['set_num'], response['name'], response['year'], response['theme_id'], response['num_parts'],response['set_img_url'],response['set_url'],response['last_modified_dt']))
|
||||
set_img_url = response["set_img_url"]
|
||||
res = requests.get(set_img_url, stream = True)
|
||||
if res.status_code == 200:
|
||||
with open("./static/sets/"+set_num+".jpg",'wb') as f:
|
||||
shutil.copyfileobj(res.raw, f)
|
||||
else:
|
||||
logging.error('set_img_url: ' + set_num)
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
elif 'add_to_list' in request.form:
|
||||
set_num = request.form.get('set_num')
|
||||
conn = sqlite3.connect('app.db')
|
||||
cursor = conn.cursor()
|
||||
rb = rebrick.init(os.getenv("REBRICKABLE_API_KEY"))
|
||||
response = json.loads(rebrick.lego.get_set(set_num).read())
|
||||
cursor.execute('''INSERT INTO wishlist (
|
||||
set_num,
|
||||
name,
|
||||
year,
|
||||
theme_id,
|
||||
num_parts,
|
||||
set_img_url,
|
||||
set_url,
|
||||
last_modified_dt
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ''', (response['set_num'], response['name'], response['year'], response['theme_id'], response['num_parts'],response['set_img_url'],response['set_url'],response['last_modified_dt']))
|
||||
set_img_url = response["set_img_url"]
|
||||
res = requests.get(set_img_url, stream = True)
|
||||
if res.status_code == 200:
|
||||
with open("./static/sets/"+set_num+".jpg",'wb') as f:
|
||||
shutil.copyfileobj(res.raw, f)
|
||||
else:
|
||||
logging.error('set_img_url: ' + set_num)
|
||||
|
||||
cursor.execute('DELETE FROM wishlist where set_num="' +set_num+ '";')
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
conn = sqlite3.connect('app.db')
|
||||
|
@ -123,6 +123,9 @@ display: none !important;
|
||||
<a class="navbar-item hidden-mobile" href="/minifigs">
|
||||
Minifigs
|
||||
</a>
|
||||
<a class="navbar-item hidden-mobile" href="/wishlist">
|
||||
Wishlist
|
||||
</a>
|
||||
<a class="navbar-item hidden-mobile" href="/config">
|
||||
Config
|
||||
</a>
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
<head>
|
||||
<title>{{ tmp }} - {{ title }}</title>
|
||||
<title>Withlist</title>
|
||||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, initial-scale=1.0"> <!-- CSS Reset -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
@ -217,7 +217,7 @@ background-color: white;
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<button id="submitButton" class="button is-primary" type="submit">Submit</button>
|
||||
<button id="submitButton" class="button is-primary" type="submit" name="create_submit">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -229,11 +229,12 @@ background-color: white;
|
||||
<table id="data" class="table tablemobile sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align:center;margin:0px;" class="fixed-width hidden-mobile">ID</th>
|
||||
<th class="fixed-width hidden-mobile">Name</th>
|
||||
<th style="text-align: center;" class="fixed-width">Year</th>
|
||||
<th style="text-align: center;" class="fixed-width">Parts</th>
|
||||
<th class="fixed-width sorttable_nosort"></th>
|
||||
<th style="text-align:center;margin:0px;" class="fixed-width">ID</th>
|
||||
<th class="fixed-width">Name</th>
|
||||
<th style="text-align: center;" class="fixed-width hidden-mobile">Year</th>
|
||||
<th style="text-align: center;" class="fixed-width hidden-mobile">Parts</th>
|
||||
<th style="text-align: center;" class="sorttable_nosort">Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody> <!-- set_num|name|year|theme_id|num_parts|set_img_url|set_url|last_modified_dt -->
|
||||
@ -242,8 +243,14 @@ background-color: white;
|
||||
<td><img src="{{ '/static/sets/' + sets[0] + '.jpg' }}" class="lightbox-trigger" style="height: 50px; width: auto;"></td>
|
||||
<td style="text-align:center;margin:0px;">{{ sets[0] }}</td>
|
||||
<td>{{ sets[1] }}</td>
|
||||
<td style="text-align:center;">{{ sets[2] }}</td>
|
||||
<td style="text-align:center;">{{ sets[4] }}</td>
|
||||
<td style="text-align:center;" class="hidden-mobile">{{ sets[2] }}</td>
|
||||
<td style="text-align:center;" class="hidden-mobile">{{ sets[4] }}</td>
|
||||
<td style="text-align:center;">
|
||||
<form method="POST" style="margin:0">
|
||||
<input type="hidden" name="set_num" value="{{ sets[0] }}">
|
||||
<button type="submit" class="btn btn-primary" name="add_to_list">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user