ak0601 commited on
Commit
0c0e192
·
verified ·
1 Parent(s): ba9edee

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -0
  2. requirements.txt +18 -0
  3. test.py +71 -0
Dockerfile ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ FROM python:3.10.9
2
+ COPY . .
3
+ WORKDIR /
4
+ RUN pip install --no-cache-dir --upgrade -r /requirements.txt
5
+ CMD ["uvicorn", "test:app", "--host", "0.0.0.0", "--port", "7860"]
requirements.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tabulate
2
+ pandas
3
+ streamlit
4
+ twilio
5
+ datetime
6
+ requests
7
+ plotly
8
+ pandas
9
+ geopy
10
+ subprocess
11
+ fastapi
12
+ vonage
13
+ threading
14
+ schedule
15
+ time
16
+ pydantic
17
+ datetime
18
+ uvicorn
test.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import vonage
2
+ # client = vonage.Client(key="712db024", secret="L4RYeQ2EWbHG6UTY")
3
+ # sms = vonage.Sms(client)
4
+ # responseData = sms.send_message(
5
+ # {
6
+ # "from": "Vonage APIs",
7
+ # "to": "917869844761",
8
+ # "text": "A text message sent using the Nexmo SMS API",
9
+ # }
10
+ # )
11
+
12
+ # if responseData["messages"][0]["status"] == "0":
13
+ # print("Message sent successfully.")
14
+ # else:
15
+ # print(f"Message failed with error: {responseData['messages'][0]['error-text']}")
16
+ from fastapi import FastAPI, HTTPException
17
+ from pydantic import BaseModel
18
+ from vonage import Client, Sms
19
+ from datetime import datetime, timedelta
20
+ import schedule
21
+ import threading
22
+ import time
23
+ import vonage
24
+
25
+ app = FastAPI()
26
+ client = vonage.Client(key="712db024", secret="L4RYeQ2EWbHG6UTY")
27
+ sms = vonage.Sms(client)
28
+
29
+ class MessageRequest(BaseModel):
30
+ phone_num: str
31
+ text: str
32
+ scheduled_time: str # HH:MM format
33
+
34
+ def send_scheduled_sms(message_request: MessageRequest):
35
+ try:
36
+ response = sms.send_message(
37
+ {
38
+ "from": "Vonage APIs",
39
+ "to": message_request.phone_num,
40
+ "text": f"This is your medicine reminder for {message_request.text}"
41
+ }
42
+ )
43
+ print(f"SMS sent to {message_request.phone_num} at {message_request.scheduled_time}")
44
+ except Exception as e:
45
+ print(f"Failed to send SMS to {message_request.phone_num}: {e}")
46
+
47
+ def schedule_daily_sms(message_request: MessageRequest):
48
+ scheduled_time = datetime.strptime(message_request.scheduled_time, "%H:%M")
49
+ schedule.every().day.at(message_request.scheduled_time).do(send_scheduled_sms, message_request)
50
+ print(f"Scheduled daily SMS for {message_request.phone_num} at {scheduled_time}")
51
+
52
+ @app.post("/send_daily_sms")
53
+ async def send_daily_sms_endpoint(message_request: MessageRequest):
54
+ schedule_daily_sms(message_request)
55
+ return {"message": f"Daily SMS scheduled for {message_request.phone_num} at {message_request.scheduled_time}"}
56
+
57
+ def run_scheduler():
58
+ while True:
59
+ schedule.run_pending()
60
+ time.sleep(1)
61
+
62
+ if __name__ == "__main__":
63
+ scheduler_thread = threading.Thread(target=schedule_daily_sms)
64
+ scheduler_thread.start()
65
+ import uvicorn
66
+
67
+ uvicorn.run(app, host="127.0.0.1", port=8000)
68
+
69
+
70
+
71
+ # uvicorn test:app --reload