-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
52 lines (32 loc) · 1.08 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import asyncio
import time
import uvicorn
from dotenv import load_dotenv
from fastapi import FastAPI, BackgroundTasks, Response, Form
from twilio.twiml.messaging_response import MessagingResponse
import card_handling
from image import upload_screenshot
from webdriver_handler import *
load_dotenv()
app = FastAPI()
global driver
@app.get("/")
async def root():
return {"message": "Hello World"}
async def getcard():
await asyncio.to_thread(card_handling.get_card)
@app.get("/get_card")
async def get_card(BackgroundTasks: BackgroundTasks):
BackgroundTasks.add_task(getcard)
return {"message": "Card requested"}
@app.get('/sms')
@app.post('/sms')
async def chat(From: str = Form(...), Body: str = Form(...)):
response = MessagingResponse()
response.message(f"Placeholder")
print(f"Text from: {From} and contains: {Body}")
return Response(content=str(response), media_type="application/xml")
# return {"message": f"Text from: {From} and contains: {Body}"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)
#TODO make this work