Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 7.7 KB

You have to be logged in to leave a comment. Sign In
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  1. from flask import Flask, request
  2. import requests
  3. import json
  4. from twilio.twiml.messaging_response import MessagingResponse
  5. app = Flask(__name__)
  6. @app.route("/")
  7. def hello():
  8. return "Bot is working!"
  9. @app.route('/bot', methods=['POST'])
  10. def bot():
  11. incoming_msg = request.values.get('Body', '')
  12. #print(incoming_msg)
  13. resp = MessagingResponse()
  14. msg = resp.message()
  15. responded = False
  16. if 'Hi' in incoming_msg or 'Hey' in incoming_msg or 'Heya' in incoming_msg or 'Menu' in incoming_msg:
  17. text = f'Hello 🙋🏽‍♂, \nThis is a Covid-Bot developed by Gagan to provide latest information updates i.e cases in different countries and create awareness to help you and your family stay safe.\n \n\n Please enter one of the following option 👇 \n *A*. Covid-19 statistics *Worldwide*. \n *B*. Covid-19 cases in *India*. \n *C*. Covid-19 cases in *China*. \n *D*. Covid-19 cases in *USA*. \n *E*. Coronavirus cases in *Italy*. \n *F*. How does it *Spread*? \n *G*. *Preventive measures* to be taken. \n *H* Self assessment Test. \n Information about COVID-19 is constantly changing. And the level of COVID-19 activity varies by community, as does the availability of testing. \n For current updates on COVID-19 and details on testing and other health measures in your state, check with your local public health agency and visit the CDC website at cdc.gov.\n\n'
  18. msg.body(text)
  19. responded = True
  20. if 'A' in incoming_msg:
  21. # return total cases
  22. r = requests.get('https://coronavirus-19-api.herokuapp.com/all')
  23. if r.status_code == 200:
  24. data = r.json()
  25. text = f'_Covid-19 Cases Worldwide_ \n\nConfirmed Cases : *{data["cases"]}* \n\nDeaths : *{data["deaths"]}* \n\nRecovered : *{data["recovered"]}* \n\n 👉 Type *B* to check cases in *India* \n 👉 Type *B, C, D, E, F, G* to see other options \n 👉 Type *Menu* to view the Main Menu'
  26. print(text)
  27. else:
  28. text = 'I could not retrieve the results at this time, sorry.'
  29. msg.body(text)
  30. responded = True
  31. if 'B' in incoming_msg or 'India' in incoming_msg:
  32. # return cases in india
  33. r = requests.get('https://coronavirus-19-api.herokuapp.com/countries/india')
  34. if r.status_code == 200:
  35. data = r.json()
  36. text = f'_Covid-19 Cases in India_ \n\nConfirmed Cases : *{data["cases"]}* \n\nToday Cases : *{data["todayCases"]}* \n\nDeaths : *{data["deaths"]}* \n\nRecovered : *{data["recovered"]}* \n\n 👉 Type *C* to check cases in *China* \n 👉 Type *A, C, D, E, F, G* to see other options \n 👉 Type *Menu* to view the Main Menu'
  37. else:
  38. text = 'I could not retrieve the results at this time, sorry.'
  39. msg.body(text)
  40. responded = True
  41. if 'C' in incoming_msg or 'China' in incoming_msg:
  42. # return cases in china
  43. r = requests.get('https://coronavirus-19-api.herokuapp.com/countries/china')
  44. if r.status_code == 200:
  45. data = r.json()
  46. text = f'_Covid-19 Cases in China_ \n\nConfirmed Cases : *{data["cases"]}* \n\nToday Cases : *{data["todayCases"]}* \n\nDeaths : *{data["deaths"]}* \n\nRecovered : *{data["recovered"]}* \n\nActive Cases : *{data["active"]}* \n\n 👉 Type *D* to check cases in *USA* \n 👉 Type *A, B, D, E, F, G* to see other options \n 👉 Type *Menu* to view the Main Menu'
  47. else:
  48. text = 'I could not retrieve the results at this time, sorry.'
  49. msg.body(text)
  50. responded = True
  51. if 'D' in incoming_msg or 'USA' in incoming_msg:
  52. # return cases in usa
  53. r = requests.get('https://coronavirus-19-api.herokuapp.com/countries/usa')
  54. if r.status_code == 200:
  55. data = r.json()
  56. text = f'_Covid-19 Cases in USA_ \n\nConfirmed Cases : *{data["cases"]}* \n\nToday Cases : *{data["todayCases"]}* \n\nDeaths : *{data["deaths"]}* \n\nRecovered : *{data["recovered"]}* \n\nActive Cases : *{data["active"]}* \n\n 👉 Type *E* to check cases in *Italy* \n 👉 Type *A, B, C, E, F, G* to see other options \n 👉 Type *Menu* to view the Main Menu'
  57. else:
  58. text = 'I could not retrieve the results at this time, sorry.'
  59. msg.body(text)
  60. responded = True
  61. if 'E' in incoming_msg or 'Italy' in incoming_msg:
  62. # return cases in italy
  63. r = requests.get('https://coronavirus-19-api.herokuapp.com/countries/italy')
  64. if r.status_code == 200:
  65. data = r.json()
  66. text = f'_Covid-19 Cases in Italy_ \n\nConfirmed Cases : *{data["cases"]}* \n\nToday Cases : *{data["todayCases"]}* \n\nDeaths : *{data["deaths"]}* \n\nRecovered : *{data["recovered"]}* \n\nActive Cases : *{data["active"]}* \n\n 👉 Type *F* to check how *Covid-19 Spreads?* \n 👉 Type *A, B, C, E, F, G* to see other options \n 👉 Type *Menu* to view the Main Menu'
  67. else:
  68. text = 'I could not retrieve the results at this time, sorry.'
  69. msg.body(text)
  70. responded = True
  71. if 'F' in incoming_msg:
  72. text = f'_Coronavirus spreads from an infected person through_ 👇 \n\n ♦ Small droplets from the nose or mouth which are spread when a person coughs or sneezes \n\n ♦ Touching an object or surface with these droplets on it and then touching your mouth, nose, or eyes before washing your hands \n \n ♦ Close personal contact, such as touching or shaking hands \n Please watch the video for more information 👇 https://youtu.be/0MgNgcwcKzE \n\n 👉 Type G to check the *Preventive Measures* \n 👉 Type *A, B, C, D, E* to see other options \n 👉 Type *Menu* to view the Main Menu'
  73. msg.body(text)
  74. msg.media('https://user-images.githubusercontent.com/34777376/77290801-f2421280-6d02-11ea-8b08-fdb516af3d5a.jpeg')
  75. responded = True
  76. if 'G' in incoming_msg:
  77. text = f'_Coronavirus infection can be prevented through the following means_ 👇 \n ✔️ Clean hand with soap and water or alcohol-based hand rub \n https://youtu.be/EJbjyo2xa2o \n\n ✔️ Cover nose and mouth when coughing & sneezing with a tissue or flexed elbow \n https://youtu.be/f2b_hgncFi4 \n\n ✔️ Avoid close contact & maintain 1-meter distance with anyone who is coughing or sneezin \n https://youtu.be/mYyNQZ6IdRk \n\n ✔️ Isolation of persons traveling from affected countries or places for at least 14 day \n https://www.mohfw.gov.in/AdditionalTravelAdvisory1homeisolation.pdf \n\n ✔️ Quarantine if advise \n https://www.mohfw.gov.in/Guidelinesforhomequarantine.pdf \n\n 👉 Type *A, B, C, D, E, F* to see other option \n 👉 Type *Menu* to view the Main Menu'
  78. msg.body(text)
  79. msg.media('https://user-images.githubusercontent.com/34777376/77290864-1c93d000-6d03-11ea-96fe-18298535d125.jpeg')
  80. responded = True
  81. if 'H' in incoming_msg:
  82. text = f' *Are you experiencing any of the following symptoms?* \n Severe difficulty breathing (for example, struggling for each breath, speaking in single words) \n Severe chest pain \n confusion (for example, unsure of where you are) \n lost consciousness'
  83. msg.body(text)
  84. responded=True
  85. if 'yes'in incoming_msg or 'y' in incoming_msg or 'YES' in incoming_msg:
  86. text = f'* Please call 911 or go directly to your nearest emergency department. *'
  87. msg.body(text)
  88. responded= True
  89. if 'no'in incoming_msg or 'n' in incoming_msg or 'NO' in incoming_msg:
  90. text = f'*STAY HOME * \n and practice social distancing '
  91. msg.body(text)
  92. responded=True
  93. if responded == False:
  94. msg.body('I only know about corona, sorry!')
  95. return str(resp)
  96. if __name__ == "__main__":
  97. app.run(host="localhost", port=5000, debug=True)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...