Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -356,5 +356,20 @@ async def mobile_process_receipts(background_tasks: BackgroundTasks, request: Re
|
|
| 356 |
@app.post('/mobile-sync')
|
| 357 |
async def sync_contacts(background_tasks: BackgroundTasks, sheeturl: str = Form(...), syncType: str = Form(...), data: str = Form(...)):
|
| 358 |
data = json.loads(data)
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
@app.post('/mobile-sync')
|
| 357 |
async def sync_contacts(background_tasks: BackgroundTasks, sheeturl: str = Form(...), syncType: str = Form(...), data: str = Form(...)):
|
| 358 |
data = json.loads(data)
|
| 359 |
+
sheetID = sheeturl.split('/')[-2]
|
| 360 |
+
body = {
|
| 361 |
+
"sheetID": sheetID,
|
| 362 |
+
"data": data,
|
| 363 |
+
"mode": "sync",
|
| 364 |
+
"syncType": syncType
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
background_tasks.add_task(post_to_url, background_tasks, appsScriptsURL, body)
|
| 368 |
+
return {"message": "Contacts processing completed."}
|
| 369 |
+
|
| 370 |
+
async def post_to_url(background_tasks: BackgroundTasks, url: str, json: dict):
|
| 371 |
+
async with httpx.AsyncClient(follow_redirects=True) as client:
|
| 372 |
+
response = await client.post(url, json=json)
|
| 373 |
+
if response.status_code != 200:
|
| 374 |
+
logging.error(f"Unexpected response from Google Apps Script API: {response.status_code} - {response.text}")
|
| 375 |
+
raise HTTPException(status_code=500, detail="Error from external API.")
|