Junaidb commited on
Commit
8be671e
·
verified ·
1 Parent(s): 50c7a9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -5,8 +5,7 @@ from fastapi.middleware.cors import CORSMiddleware
5
  from pydantic import BaseModel
6
  from components.dbconnection import provideClient
7
 
8
-
9
-
10
 
11
 
12
 
@@ -42,7 +41,6 @@ class PPD(BaseModel):
42
  renewal:bool
43
 
44
 
45
-
46
  @app.post("/dataingestion")
47
  async def Ingest(request:PPD):
48
 
@@ -62,7 +60,30 @@ async def Ingest(request:PPD):
62
 
63
 
64
  }
 
65
  result = coll.insert_one(payload)
66
  print(f"Inserted ID: {result.inserted_id}")
67
 
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from pydantic import BaseModel
6
  from components.dbconnection import provideClient
7
 
8
+ from fastapi.responses import HTMLResponse
 
9
 
10
 
11
 
 
41
  renewal:bool
42
 
43
 
 
44
  @app.post("/dataingestion")
45
  async def Ingest(request:PPD):
46
 
 
60
 
61
 
62
  }
63
+
64
  result = coll.insert_one(payload)
65
  print(f"Inserted ID: {result.inserted_id}")
66
 
67
 
68
+
69
+ @app.post("/webhook")
70
+ async def tally_webhook(request: Request):
71
+ # 1. Get the raw JSON from Tally
72
+ payload = await request.json()
73
+
74
+ # 2. Extract the list of answers
75
+ # Tally's data lives in payload['data']['fields']
76
+ fields = payload.get("data", {}).get("fields", [])
77
+
78
+ # 3. Convert that list into a simple Python dictionary
79
+ # This maps the "Label" of your question to the "Value" the user typed
80
+ answers = {field['label']: field['value'] for field in fields}
81
+
82
+ # 4. Use your data!
83
+ print(f"New Submission!")
84
+ print(f"Name: {answers.get('Name')}")
85
+ print(f"Regi: {answers.get('Regi')}")
86
+ print(f"Address: {answers.get('Address')}")
87
+
88
+ return {"status": "success"}
89
+