1
+ from flask import Flask , request
2
+ from twilio .rest import Client
3
+ from test1 import send_message
4
+ import time
5
+ import findCounty as fc
6
+ from nearestCentersDictionary import nearest_centers
7
+ from makeMessage import formulate_message
8
+ from test import cases_data
9
+ import os , ssl
10
+ import random
11
+ from puns import puns
12
+ if (not os .environ .get ('PYTHONHTTPSVERIFY' , '' ) and getattr (ssl , '_create_unverified_context' , None )):
13
+ ssl ._create_default_https_context = ssl ._create_unverified_context
14
+
15
+
16
+ app = Flask (__name__ )
17
+ account_sid = 'AC0d79e56293d4494c36eee4f48a59ff8e'
18
+ auth_token = '8816dfab39966ecfce99deb9a111a320'
19
+ client = Client (account_sid , auth_token )
20
+ bot_number = "+14155238886"
21
+
22
+ user_zips = {}
23
+ myths = [
24
+ 'Covid-19 is not waterborne; however, it is aerosolic and airborne' ,
25
+ 'Covid-19 is not created in a lab as conspiracy theorists would say' ,
26
+ 'No you cannot get a face-mask exception card. You must wear a mask to stop the infection from spreading' ,
27
+ 'Injecting or drinking products such as alcohol and bleach will not make you immmune to Covid-19 or cure you if you tested positive' ,
28
+ 'Ordering products from overseas will not make you or your family sick from Covid-19' ,
29
+ 'Masks absolutely help stop the disease. Be mindful when going out and meeting with others please'
30
+ ]
31
+ bye_statements = ["bye" , 'leave' , 'exit' , 'quit' , 'goodbye' ]
32
+
33
+ @app .route ("/" )
34
+ def hello ():
35
+ return "Hello, World!"
36
+
37
+ @app .route ("/sms" , methods = ['POST' ])
38
+ def sms_reply ():
39
+ msg = request .form .get ('Body' )
40
+ phone_no = request .form .get ('From' )
41
+ responded = False
42
+
43
+ if msg .lower () == "Hi" .lower () or msg .lower () == "hello" .lower ():
44
+ send_message ("Hi There! I'm CovidBot. I'm here to help you navigate your way through this pandemic safely." , bot_number , phone_no )
45
+ time .sleep (0.8 )
46
+ #responded = send_menu(bot_number, phone_no)
47
+ #time.sleep(0.9)
48
+ send_message ("Your zip code is needed for some of the main features. Please supply your zip code: " , bot_number , phone_no )
49
+
50
+ elif msg .lower () == "joke" .lower ():
51
+ send_message ("Hippos are blue?" , bot_number , phone_no )
52
+
53
+ #latest numbers
54
+ elif msg == 'A' :
55
+ if phone_no in user_zips .keys ():
56
+ zip = user_zips [phone_no ][0 ]
57
+ county = fc .find_county_by_zip_code (zip )
58
+ if county [1 ] == "No" :
59
+ send_message ("Enter a valid zip code. Otherwise, I'm sorry, I cannot retrieve data for you :(" , bot_number , phone_no )
60
+ elif county [0 ] == 2 :
61
+ send_message ("Which county are you located in: {}" .format (county [1 ]), bot_number , phone_no )
62
+ # length 1, no need for more user input
63
+ else :
64
+ #county = fc.find_county_by_zip_code(zip)
65
+ data = cases_data (county [1 ])
66
+ send_message ("Data for {} county:\n "
67
+ ""
68
+ "There are {} confirmed cases\n "
69
+ "{} deaths in total\n "
70
+ "{} have recovered from Covid-19\n "
71
+ "The number of active cases is at {}\n "
72
+ ""
73
+ "The incidence rate (number of new cases) is {}\n "
74
+ ""
75
+ "The mortality rate lies at {}." .format (data [- 1 ], data [0 ], data [1 ], data [2 ], data [3 ], round (data [4 ], 2 ), str (round (data [5 ], 2 )) + "%" ), bot_number , phone_no )
76
+ else :
77
+ send_message ("Supply a zip code:" , bot_number , phone_no )
78
+
79
+ #store zip_code (OPERATIONAL)
80
+ elif len (list (msg )) == 5 :
81
+ #make sure there are no duplicates or if the first time, there is an incorrect value, get rid of it to store new value
82
+ print (user_zips )
83
+ if phone_no not in user_zips .keys ():
84
+ user_zips [phone_no ] = [int (msg )]
85
+ else :
86
+ del user_zips [phone_no ]
87
+ user_zips [phone_no ] = [int (msg )]
88
+ send_message ("Got it!" , bot_number , phone_no )
89
+ time .sleep (0.8 )
90
+ responded = send_menu (bot_number , phone_no )
91
+
92
+ #myths debunked (OPERATIONAL)
93
+ elif msg .lower () == 'B' .lower ():
94
+ sent = random .choice (myths )
95
+ send_message (sent , bot_number , phone_no )
96
+
97
+ #nearest test centers
98
+ elif msg .lower () == 'C' .lower ():
99
+ if phone_no in user_zips .keys ():
100
+ search = str (user_zips [phone_no ][0 ]) + ", New York"
101
+ centers = nearest_centers [search ]
102
+
103
+ first_test_center = formulate_message (centers [0 ][1 ])
104
+ second_test_center = formulate_message (centers [1 ][1 ])
105
+ third_test_center = formulate_message (centers [2 ][1 ])
106
+ fourth_test_center = formulate_message (centers [3 ][1 ])
107
+ fifth_test_center = formulate_message (centers [4 ][1 ])
108
+
109
+ print (first_test_center , fourth_test_center )
110
+ send_message (first_test_center + "\n " + " " + "\n " + second_test_center + "\n " + " " + "\n " + third_test_center + "\n " + " " + "\n " + fourth_test_center + "\n " + " " + "\n " + fifth_test_center , bot_number , phone_no )
111
+ '''
112
+ send_message(formulate_message(centers[1][1]), bot_number, phone_no)
113
+ time.sleep(1)
114
+ send_message(formulate_message(centers[2][1]), bot_number, phone_no)
115
+ time.sleep(1)
116
+ send_message(formulate_message(centers[3][1]), bot_number, phone_no)'''
117
+ else :
118
+ send_message ("Please provide a zip code and re-enter the letter you typed: " , bot_number , phone_no )
119
+
120
+ elif msg .lower () == 'D' .lower ():
121
+ send_message ("Type the number of the friend you want to share with: " , bot_number , phone_no )
122
+
123
+ elif msg .lower () == 'E' .lower ():
124
+ send_message ("Your help is needed!" , bot_number , phone_no )
125
+ time .sleep (0.5 )
126
+ send_message ("https://www.unicefusa.org/?form=HealthEmergency&utm_content=corona3responsive_E2001&ms=cpc_dig_2020_Emergencies_20200402_google_corona3responsive_delve_E2001&initialms=cpc_dig_2020_Emergencies_20200402_google_corona3responsive_delve_E2001&gclid=CjwKCAjwm_P5BRAhEiwAwRzSOyezPDpOahj2yFSuxeaXR9PKRUTNn9vkwjfOJIznTwkXF-0-HuJuFBoCdzkQAvD_BwE" , bot_number , phone_no )
127
+
128
+ elif msg .lower () == 'F' .lower ():
129
+ send_message ("Covid-19 Cases: https://coronavirus.jhu.edu/map.html" , bot_number , phone_no )
130
+ time .sleep (1 )
131
+ send_message ("Covid-19 Updates: https://www.nytimes.com/news-event/coronavirus?name=styln-coronavirus®ion=TOP_BANNER&variant=1_Show&block=storyline_menu_recirc&action=click&pgtype=Article&impression_id=b0067c50-e244-11ea-8a15-e95204810ae6" , bot_number , phone_no )
132
+
133
+ elif len (list (msg )) == 10 or len (list (msg )) == 11 or len (list (msg )) == 12 :
134
+ if len (list (msg )) == 10 :
135
+ number = "+1" + str (msg )
136
+ send_message ("Hi There, I am CovidBot! I am a chatbot that helps guide you through the pandemic with truthful and insightful info.\n "
137
+ "Your friend, whose number is {} share me with you." .format (number ), bot_number , number )
138
+
139
+ elif len (list (msg )) == 11 :
140
+ number = "+" + str (msg )
141
+ send_message (
142
+ "Hi There, I am CovidBot! I am a chatbot that helps guide you through the pandemic with truthful and insightful info.\n "
143
+ "Your friend, whose number is {} share me with you." .format (number ), bot_number , number )
144
+
145
+ elif len (list (msg )) == 12 :
146
+ print (msg )
147
+ send_message (
148
+ "Hi There, I am CovidBot! I am a chatbot that helps guide you through the pandemic with truthful and insightful info.\n "
149
+ "Your friend, whose number is {} share me with you. Say Hi to activate" .format (msg ), bot_number , msg )
150
+
151
+ else :
152
+ send_message ("Check if you formatted the number correct. There seems to be a mistake." , bot_number , phone_no )
153
+
154
+ elif msg == "Puns123**" :
155
+ pun = random .choice (puns )
156
+ send_message (pun ["pun" ], bot_number , phone_no )
157
+ time .sleep (2 )
158
+ send_message (pun ["punchline" ], bot_number , phone_no )
159
+
160
+ elif msg .lower () in bye_statements :
161
+ send_message ("Goodbye" , bot_number , phone_no )
162
+
163
+ else :
164
+ send_message ("I don't understand. Here is the menu again: " , bot_number , phone_no )
165
+ responded = send_menu (bot_number , phone_no )
166
+
167
+ return "ok"
168
+
169
+ def send_menu (bot_num , phone_no ):
170
+ keyword = "Menu: \n " \
171
+ "Type 'A' -> Get Info on Cases\n " \
172
+ "Type 'B' -> Debunk those myths!\n " \
173
+ "Type 'C' -> Finds your nearest test sites\n " \
174
+ "Type 'D' -> Share this bot!\n " \
175
+ "Type 'E' -> Donate for Covid-19\n " \
176
+ "Type 'F' -> More Information about the virus"
177
+
178
+ send_message (keyword , bot_num , phone_no )
179
+ return True
180
+
181
+ if __name__ == "__main__" :
182
+ app .run (debug = True )
0 commit comments