Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,18 +115,15 @@ async def post_to_google_apps_script(appsScriptsURL, body, s3_orginal_url):
|
|
| 115 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 116 |
await record_failure(s3_orginal_url, 'Failed to queue processed image.', body.sheetID)
|
| 117 |
|
| 118 |
-
async def background_worker(sheeturl, image_contents, filename, content_type, appsScriptsURL):
|
| 119 |
sheetID = sheeturl.split('/')[-2]
|
| 120 |
-
|
| 121 |
-
user_doc = users_ref.document(sheetID)
|
| 122 |
# get the 'total_uploaded' field from the user's document
|
| 123 |
user_data = user_doc.get().to_dict()
|
| 124 |
logging.info(user_data)
|
| 125 |
|
| 126 |
if user_data is None:
|
| 127 |
logging.info('user not found')
|
| 128 |
-
user_doc = users_ref.document('xJs8nDUdbVWvq1QIKY3VYmFkidn1')
|
| 129 |
-
logging.info(user_doc)
|
| 130 |
await record_failure('', 'User not found.', sheetID)
|
| 131 |
return {"message": "User not found."}
|
| 132 |
total_uploaded = user_data.get('total_uploaded', 0)
|
|
@@ -206,7 +203,7 @@ async def mobile_process_receipts(background_tasks: BackgroundTasks, sheeturl: s
|
|
| 206 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 207 |
raise HTTPException(status_code=500, detail="Error from external API.")
|
| 208 |
|
| 209 |
-
background_tasks.add_task(background_worker, sheeturl, image_contents, uuid, image.content_type, appsScriptsURL, )
|
| 210 |
|
| 211 |
return {"message": "Image processing completed."}
|
| 212 |
|
|
@@ -251,7 +248,7 @@ async def mobile_process_receipts(background_tasks: BackgroundTasks, request: Re
|
|
| 251 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 252 |
raise HTTPException(status_code=500, detail="Error from external API.")
|
| 253 |
|
| 254 |
-
background_tasks.add_task(background_worker, sheeturl, image_contents, uuid, content_type, appsScriptsURL)
|
| 255 |
|
| 256 |
return {"message": "Image processing completed."}
|
| 257 |
|
|
@@ -345,7 +342,7 @@ async def cutting_image(masked_image, image_contents, cut_images, s3_orginal_url
|
|
| 345 |
|
| 346 |
|
| 347 |
@app.post('/test')
|
| 348 |
-
async def mobile_process_receipts(background_tasks: BackgroundTasks, sheeturl: str = Form(...),
|
| 349 |
image_contents = await image.read()
|
| 350 |
uuid = str(uuid4())
|
| 351 |
timestamp = str(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))
|
|
|
|
| 115 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 116 |
await record_failure(s3_orginal_url, 'Failed to queue processed image.', body.sheetID)
|
| 117 |
|
| 118 |
+
async def background_worker(sheeturl, image_contents, filename, content_type, appsScriptsURL, user_ref):
|
| 119 |
sheetID = sheeturl.split('/')[-2]
|
| 120 |
+
user_doc = users_ref.document(user_ref)
|
|
|
|
| 121 |
# get the 'total_uploaded' field from the user's document
|
| 122 |
user_data = user_doc.get().to_dict()
|
| 123 |
logging.info(user_data)
|
| 124 |
|
| 125 |
if user_data is None:
|
| 126 |
logging.info('user not found')
|
|
|
|
|
|
|
| 127 |
await record_failure('', 'User not found.', sheetID)
|
| 128 |
return {"message": "User not found."}
|
| 129 |
total_uploaded = user_data.get('total_uploaded', 0)
|
|
|
|
| 203 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 204 |
raise HTTPException(status_code=500, detail="Error from external API.")
|
| 205 |
|
| 206 |
+
background_tasks.add_task(background_worker, sheeturl, image_contents, uuid, image.content_type, appsScriptsURL, user_ref)
|
| 207 |
|
| 208 |
return {"message": "Image processing completed."}
|
| 209 |
|
|
|
|
| 248 |
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 249 |
raise HTTPException(status_code=500, detail="Error from external API.")
|
| 250 |
|
| 251 |
+
background_tasks.add_task(background_worker, sheeturl, image_contents, uuid, content_type, appsScriptsURL, user_ref)
|
| 252 |
|
| 253 |
return {"message": "Image processing completed."}
|
| 254 |
|
|
|
|
| 342 |
|
| 343 |
|
| 344 |
@app.post('/test')
|
| 345 |
+
async def mobile_process_receipts(background_tasks: BackgroundTasks, sheeturl: str = Form(...), user_ref: str = Form(...), image: UploadFile = File(...)):
|
| 346 |
image_contents = await image.read()
|
| 347 |
uuid = str(uuid4())
|
| 348 |
timestamp = str(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"))
|