Skip to content

Commit

Permalink
Refactor reset
Browse files Browse the repository at this point in the history
  • Loading branch information
laurynas committed Mar 17, 2024
1 parent 4763ac0 commit 47ad9b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import json
from PIL import Image
from src.digitizer import Digitizer
from src.routing import IdentifierConverter
from io import BytesIO
from glob import glob
from flask import Flask, request
import json


model = 'models/yolov8-detect-20240229.onnx'
data_dir = 'data/'
Expand Down Expand Up @@ -69,18 +71,14 @@ def meter_image(meter_id):

@app.route('/meter/<identifier:meter_id>/reset', methods=['GET'])
def reset_meter(meter_id):
value = request.args.get('value', type=float)
json_file = os.path.join(data_dir, f'{meter_id}.json')
image_file = os.path.join(data_dir, f'{meter_id}.jpg')

if os.path.exists(json_file):
os.remove(json_file)

if os.path.exists(image_file):
os.remove(image_file)
for file in glob(f'{data_dir}{meter_id}.*'):
os.remove(file)

value = request.args.get('value', default=None, type=float)

if value is not None:
json_data = json.dumps({'value': value})
json_file = os.path.join(data_dir, f'{meter_id}.json')
with open(json_file, 'w') as f:
f.write(json_data)

Expand Down
2 changes: 1 addition & 1 deletion src/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
class IdentifierConverter(BaseConverter):
def __init__(self, url_map, *items):
super(IdentifierConverter, self).__init__(url_map)
self.regex = r"[0-9a-zA-Z]{1,20}"
self.regex = r"[0-9a-zA-Z\-]{1,20}"

0 comments on commit 47ad9b4

Please sign in to comment.