2024-03-04 18:17:19 +01:00
|
|
|
from flask import Flask, request, redirect, jsonify, render_template
|
2024-02-28 20:08:16 +01:00
|
|
|
import json
|
2024-02-29 14:47:12 +01:00
|
|
|
from pprint import pprint as pp
|
2024-03-03 11:15:38 +01:00
|
|
|
from pathlib import Path
|
|
|
|
import re
|
2024-02-28 20:08:16 +01:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
2024-02-29 19:44:28 +01:00
|
|
|
#tmp = '71386-10'
|
2024-02-28 21:31:43 +01:00
|
|
|
|
2024-03-03 11:15:38 +01:00
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
|
|
|
pathlist = Path('./info/').rglob('*.json')
|
|
|
|
set_list = []
|
|
|
|
for path in pathlist:
|
2024-03-03 12:43:24 +01:00
|
|
|
set_num = re.findall(r"\b\d+(?:-\d+)?\b",str(path))[0]
|
|
|
|
with open('./static/sets/'+set_num+'/info.json') as info:
|
|
|
|
info_file = json.loads(info.read())
|
|
|
|
set_list.append(info_file)
|
|
|
|
return render_template('frontpage.html',set_list=set_list)
|
2024-03-03 11:15:38 +01:00
|
|
|
|
2024-02-29 19:44:28 +01:00
|
|
|
@app.route('/<tmp>')
|
2024-03-03 11:15:38 +01:00
|
|
|
def sets(tmp):
|
2024-03-03 12:43:24 +01:00
|
|
|
with open('./static/sets/'+tmp+'/info.json') as info:
|
2024-02-28 21:31:43 +01:00
|
|
|
info_file = json.loads(info.read())
|
2024-03-03 12:43:24 +01:00
|
|
|
with open('./static/sets/'+tmp+'/inventory.json') as inventory:
|
2024-02-28 21:31:43 +01:00
|
|
|
inventory_file = json.loads(inventory.read())
|
2024-02-29 13:24:47 +01:00
|
|
|
with open('./info/'+tmp+'.json') as info:
|
|
|
|
json_file = json.loads(info.read())
|
2024-03-04 20:00:57 +01:00
|
|
|
return render_template('bootstrap_table.html', tmp=tmp,title=info_file['name'],
|
2024-02-29 13:24:47 +01:00
|
|
|
info_file=info_file,inventory_file=inventory_file,json_file=json_file)
|
2024-02-28 20:08:16 +01:00
|
|
|
|
|
|
|
|
2024-02-29 19:44:28 +01:00
|
|
|
@app.route('/<tmp>/saveNumber', methods=['POST'])
|
|
|
|
def save_number(tmp):
|
2024-03-04 15:41:48 +01:00
|
|
|
part_num = request.form.get('brick.part.part_num')
|
|
|
|
color = request.form.get('brick.color.name')
|
|
|
|
index = request.form.get('index')
|
2024-02-28 20:08:16 +01:00
|
|
|
number = request.form.get('numberInput')
|
2024-03-02 09:02:37 +01:00
|
|
|
is_spare = request.form.get('is_spare')
|
2024-02-28 20:08:16 +01:00
|
|
|
|
|
|
|
if number is not None:
|
2024-02-28 21:31:43 +01:00
|
|
|
|
2024-03-04 15:41:48 +01:00
|
|
|
print(part_num)
|
|
|
|
print(color)
|
2024-02-28 21:31:43 +01:00
|
|
|
print(number)
|
2024-03-02 09:02:37 +01:00
|
|
|
print(is_spare)
|
2024-02-28 21:31:43 +01:00
|
|
|
|
|
|
|
with open('./info/'+tmp+'.json') as info:
|
|
|
|
json_file = json.loads(info.read())
|
|
|
|
print(json_file['count'])
|
|
|
|
|
2024-03-04 15:41:48 +01:00
|
|
|
data = '{"brick" : {"ID":"' + part_num + '","is_spare": "' + is_spare + '","color_name": "' + color + '","amount":"' + number + '"}}'
|
2024-02-29 15:22:55 +01:00
|
|
|
|
2024-03-04 18:17:19 +01:00
|
|
|
if len(json_file['unit'][int(index)]['bricks']['missing']) == 0:
|
|
|
|
json_file['unit'][int(index)]['bricks']['missing'].append(json.loads(data))
|
|
|
|
print(json_file)
|
|
|
|
elif number == '0':
|
|
|
|
for idx,i in enumerate(json_file['unit'][int(index)]['bricks']['missing']):
|
|
|
|
if i['brick']['ID'] == part_num and i['brick']['is_spare'] == is_spare and i['brick']['color_name'] == color:
|
|
|
|
json_file['unit'][int(index)]['bricks']['missing'].pop(0)
|
|
|
|
else:
|
|
|
|
found = False
|
|
|
|
|
|
|
|
for idx,i in enumerate(json_file['unit'][int(index)]['bricks']['missing']):
|
|
|
|
if not found and i['brick']['ID'] == part_num and i['brick']['is_spare'] == is_spare and i['brick']['color_name'] == color:
|
|
|
|
print('found one ')
|
|
|
|
print(part_num,i['brick']['ID'])
|
|
|
|
print(is_spare,i['brick']['is_spare'])
|
|
|
|
print(color,i['brick']['color_name'])
|
2024-02-29 15:22:55 +01:00
|
|
|
|
2024-03-04 18:17:19 +01:00
|
|
|
json_file['unit'][int(index)]['bricks']['missing'][idx]['brick']['amount'] = number
|
|
|
|
found = True
|
|
|
|
if not found:
|
|
|
|
json_file['unit'][int(index)]['bricks']['missing'].append(json.loads(data))
|
2024-03-04 15:41:48 +01:00
|
|
|
|
|
|
|
if not number == '':
|
|
|
|
with open('./info/'+tmp+'.json', 'w') as dump_file:
|
|
|
|
json.dump(json_file,dump_file)
|
|
|
|
|
2024-03-04 18:17:19 +01:00
|
|
|
return redirect('/{}'.format(tmp))
|
2024-02-28 20:08:16 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2024-02-29 08:43:31 +01:00
|
|
|
app.run(host='192.168.10.109', debug=True, port=3333)
|