intégration backend / api

backend avec api d'ajout d'avis (note principale uniquement)
This commit is contained in:
Quentin Roussel
2023-03-23 11:14:46 +01:00
parent e097c1fd23
commit 90a7d20250
5 changed files with 33 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
import requests
import asyncio
import json
import os
@@ -23,6 +24,7 @@ class WebsocketServer(threading.Thread):
async def handler(self,websocket):
while True:
for msg in self.messageQueue:
# print("sending", json.dumps(msg))
await websocket.send(json.dumps(msg))
self.messageQueue.pop(0)
await asyncio.sleep(0.01)
@@ -34,4 +36,14 @@ class ApiClient():
def __init__(self, host=os.getenv("API_HOST"), port=os.getenv("API_PORT")):
self.host = host
self.port = port
def send(self,note,note_autre):
#Exemple ajout d'un commentaire depuis la borne (site ou geste)
avis = {
"note": note,
"source": "borne",
"commentaire":"",
#Optionel
"notes_autre": '{"proprete":'+str(note_autre)+',"calme":10}',
}
return requests.post("http://"+self.host+":"+self.port+"/add_review", data=avis)