BrickTracker/app.py

57 lines
1.5 KiB
Python
Raw Normal View History

2024-02-28 20:08:16 +01:00
from flask import Flask, request, jsonify, render_template
import json
app = Flask(__name__)
2024-02-28 21:31:43 +01:00
tmp = '71386-10'
2024-02-28 20:08:16 +01:00
@app.route('/')
def index():
2024-02-28 21:31:43 +01:00
with open('./sets/'+tmp+'/info.json') as info:
info_file = json.loads(info.read())
with open('./sets/'+tmp+'/inventory.json') as inventory:
inventory_file = json.loads(inventory.read())
return render_template('bootstrap_table.html', title=info_file['set_num']+" - "+info_file['name'],
info_file=info_file,inventory_file=inventory_file)
#return render_template('index.html')
2024-02-28 20:08:16 +01:00
#'Welcome to the Flask App'
@app.route('/saveNumber', methods=['POST'])
def save_number():
2024-02-28 21:31:43 +01:00
data1 = request.form.get('brick.part.part_num')
data2 = request.form.get('brick.color.name')
2024-02-28 20:08:16 +01:00
number = request.form.get('numberInput')
if number is not None:
2024-02-28 21:31:43 +01:00
print(data1)
print(data2)
print(number)
with open('./info/'+tmp+'.json') as info:
json_file = json.loads(info.read())
print(json_file['count'])
2024-02-29 08:17:19 +01:00
data = '''
{
"brick" : {
"ID": ''' + data1 + ''',
"color_name": ''' + data2 + ''',
"amount":''' + number + '''
}
}
'''
json_file['unit'][0]['bricks']['missing'].append(data)
2024-02-28 21:31:43 +01:00
2024-02-28 20:08:16 +01:00
# Save number to JSON file
with open('data.json', 'w') as json_file:
2024-02-29 08:17:19 +01:00
json.dump(json_file, json_file)
2024-02-28 21:31:43 +01:00
return ('', 204)
2024-02-28 20:08:16 +01:00
if __name__ == '__main__':
2024-02-29 08:17:19 +01:00
app.run(host='23.88.46.240', debug=True, port=3333)