Rahul-Samedavar commited on
Commit
f7edd7e
·
1 Parent(s): b2f9d49
Files changed (4) hide show
  1. .gitignore +1 -0
  2. Dockerfile +13 -0
  3. main.py +49 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ env
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import requests
4
+
5
+ app = FastAPI()
6
+
7
+ EXPO_TOKENS = set()
8
+
9
+ class RegisterRequest(BaseModel):
10
+ expo_token: str
11
+
12
+ class IncidentRequest(BaseModel):
13
+ incident_id: str = 1
14
+ title: str = "Dummy Title"
15
+ message: str = "message"
16
+
17
+ dummyData = IncidentRequest()
18
+
19
+ @app.post("/register")
20
+ def register_device(data: RegisterRequest):
21
+ EXPO_TOKENS.add(data.expo_token)
22
+ print(data.expo_token)
23
+ return {"status": "registered"}
24
+
25
+ @app.get("/notify-incident")
26
+ def notify_incident():
27
+ data=dummyData
28
+ responses = []
29
+
30
+ for token in EXPO_TOKENS:
31
+ payload = {
32
+ "to": token,
33
+ "sound": "default",
34
+ "title": data.title,
35
+ "body": data.message,
36
+ "priority": "high",
37
+ "data": {
38
+ "url": f"myapp://incidents/{data.incident_id}"
39
+ },
40
+ }
41
+
42
+ r = requests.post(
43
+ "https://exp.host/--/api/v2/push/send",
44
+ json=payload,
45
+ timeout=5,
46
+ )
47
+ responses.append(r.json())
48
+
49
+ return {"sent": len(responses)}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ uvicorn
2
+ fastapi
3
+ requests
4
+ pydantic