diff --git a/.idea/Covid19-chatbot.iml b/.idea/Covid19-chatbot.iml index 5b48ddd..8388dbc 100644 --- a/.idea/Covid19-chatbot.iml +++ b/.idea/Covid19-chatbot.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 90e2a6a..f6104af 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/DataRequests/MakeApiRequests.py b/DataRequests/MakeApiRequests.py index b86d491..3b16b28 100644 --- a/DataRequests/MakeApiRequests.py +++ b/DataRequests/MakeApiRequests.py @@ -1,5 +1,7 @@ import requests import json + + class Api: def __init__(self): pass @@ -9,7 +11,7 @@ def makeApiRequestForCounrty(self, country_name): querystring = {"country": country_name} headers = { 'x-rapidapi-host': "covid-193.p.rapidapi.com", - 'x-rapidapi-key': "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e" + 'x-rapidapi-key': "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888" } response = requests.request("GET", url, headers=headers, params=querystring) # print(response.text) @@ -18,34 +20,30 @@ def makeApiRequestForCounrty(self, country_name): result = js.get('response')[0] print(result.get('cases')) print("*" * 20) - return result.get('cases') , result.get('deaths'),result.get('tests') - + return result.get('cases'), result.get('deaths'), result.get('tests') def makeApiRequestForIndianStates(self): - url = "https://covid19-data.p.rapidapi.com/india" + url = "https://covid-193.p.rapidapi.com/history?country=india&day=2022-04-17" headers = { - 'x-rapidapi-host': "covid19-data.p.rapidapi.com", - 'x-rapidapi-key': "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e" + 'x-rapidapi-host': "covid-193.p.rapidapi.com", + 'x-rapidapi-key': "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888" } response = requests.request("GET", url, headers=headers) # print(response.text) js = json.loads(response.text) print("******", js) - #result = js.get('list') + # result = js.get('list') return js - def makeApiWorldwide(self): - url = "https://covid-19-statistics.p.rapidapi.com/reports/total" + url = "https://covid-193.p.rapidapi.com/countries" headers = { - "x-rapidapi-host": "covid-19-statistics.p.rapidapi.com", - "x-rapidapi-key": "482a8f8516msh16204eb9d1f4f68p1a9146jsnf33914c7300e" + "x-rapidapi-host": "covid-193.p.rapidapi.com", + "x-rapidapi-key": "36626c56f2msh8580d29c47aca59p12a368jsnc74c1cdf1888" } response = requests.request("GET", url, headers=headers) # print(response.text) js = json.loads(response.text) print("******", js) result = js.get('data') - return result - diff --git a/DataRequests/__pycache__/MakeApiRequests.cpython-39.pyc b/DataRequests/__pycache__/MakeApiRequests.cpython-39.pyc new file mode 100644 index 0000000..e8b3877 Binary files /dev/null and b/DataRequests/__pycache__/MakeApiRequests.cpython-39.pyc differ diff --git a/README.md b/README.md index 15c340f..ea03a36 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ -# As requested by many people over mail or linkedin.I am making stepwise Implementation playist on youtube. - -Here is the link of stepwise implementation Youtube- https://bit.ly/3c0n0ss - -# End-to-End Covid-19 chatbot using DialogFlow,Python/Flask,MongoDb Atlas and deployed on Pivotal Cloud foundary and Telegram +# End-to-End Covid-19 chatbot using DialogFlow,Python/Flask,MongoDb Atlas and deployed on Heroku and Telegram This chatbot developed using Dialoglow,python,flask,MongoDB and deployed on Telegram. search @bestcovid19_bot on telegram app BestCovid-19 Bot can give answers of all of your queries related to covid-19 also it can - @@ -27,7 +23,7 @@ If you like my work kindly hit 🌟🌟🌟 How to Setup the whole system ? -1. Setup Pivotal Cloud foundary account and install foundary CLI to your system +1. Setup Heroku account 2. Setup MongoDB Atlas account @@ -42,5 +38,5 @@ How to Setup the whole system ? 5. use PostMan to test this code locally. localhost:5000/webhook , give header and body as Raw json. (Everything mentioned inside document.) -feel free to contact me in case of any problem reachout to me @ 'dineshraturi22@gmail.com' and Add subject-BestCovid Github Query +feel free to contact me in case of any problem reachout to 'navneetguptaend@gmail .com' and Add subject-BestCovid Github Query diff --git a/app.py b/app.py index f7aa832..dabd5bd 100644 --- a/app.py +++ b/app.py @@ -1,19 +1,22 @@ # doing necessary imports -from flask import Flask, render_template, request, jsonify, make_response -from flask_cors import CORS, cross_origin -import requests -import pymongo import json -import os -from saveConversation import Conversations +import pymongo +import requests + +from flask import Flask, render_template, request, jsonify, make_response +from flask_cors import cross_origin +from pymongo import MongoClient + from DataRequests import MakeApiRequests +from saveConversation import Conversations from sendEmail import EMailClient -from pymongo import MongoClient + +import os app = Flask(__name__) # initialising the flask app with the name 'app' -# geting and sending response to dialogflow +# getting and sending response to dialogflow @app.route('/webhook', methods=['POST']) @cross_origin() def webhook(): @@ -29,7 +32,7 @@ def webhook(): # processing the request from dialogflow def processRequest(req): # dbConn = pymongo.MongoClient("mongodb://localhost:27017/") # opening a connection to Mongo - log = Conversations.Log() + # log = Conversations.Log() sessionID = req.get('responseId') result = req.get("queryResult") intent = result.get("intent").get('displayName') @@ -38,11 +41,11 @@ def processRequest(req): cust_name = parameters.get("cust_name") cust_contact = parameters.get("cust_contact") cust_email = parameters.get("cust_email") - db = configureDataBase() + # db = configureDataBase() if intent == 'covid_searchcountry': cust_country = parameters.get("geo-country") - if(cust_country=="United States"): + if cust_country == "United States": cust_country = "USA" fulfillmentText, deaths_data, testsdone_data = makeAPIRequest(cust_country) @@ -55,8 +58,8 @@ def processRequest(req): deaths_data.get('new')) + \ "\n" + " Total Test Done : " + str(deaths_data.get('total')) + "\n\n*******END********* \n " print(webhookresponse) - log.saveConversations(sessionID, cust_country, webhookresponse, intent, db) - log.saveCases( "country", fulfillmentText, db) + # log.saveConversations(sessionID, cust_country, webhookresponse, intent, db) + # log.saveCases("country", fulfillmentText, db) return { @@ -82,13 +85,13 @@ def processRequest(req): } elif intent == "Welcome" or intent == "continue_conversation" or intent == "not_send_email" or intent == "endConversation" or intent == "Fallback" or intent == "covid_faq" or intent == "select_country_option": fulfillmentText = result.get("fulfillmentText") - log.saveConversations(sessionID, query_text, fulfillmentText, intent, db) + # log.saveConversations(sessionID, query_text, fulfillmentText, intent, db) elif intent == "send_report_to_email": fulfillmentText = result.get("fulfillmentText") - log.saveConversations(sessionID, "Sure send email", fulfillmentText, intent, db) - val = log.getcasesForEmail("country", "", db) - print("===>",val) - prepareEmail([cust_name, cust_contact, cust_email,val]) + # log.saveConversations(sessionID, "Sure send email", fulfillmentText, intent, db) + # val = log.getcasesForEmail("country", "", db) + # print("===>", val) + # prepareEmail([cust_name, cust_contact, cust_email, val]) elif intent == "totalnumber_cases": fulfillmentText = makeAPIRequest("world") @@ -102,8 +105,8 @@ def processRequest(req): "\n" + " Last updated : " + str( fulfillmentText.get('last_update')) + "\n\n*******END********* \n " print(webhookresponse) - log.saveConversations(sessionID, "Cases worldwide", webhookresponse, intent, db) - #log.saveCases("world", fulfillmentText, db) + # log.saveConversations(sessionID, "Cases worldwide", webhookresponse, intent, db) + # log.saveCases("world", fulfillmentText, db) return { @@ -136,7 +139,7 @@ def processRequest(req): webhookresponse1 = '' webhookresponse2 = '' webhookresponse3 = '' - for i in range(0,11): + for i in range(0, 11): webhookresponse = fulfillmentText[i] # print(webhookresponse['state']) # js = json.loads(webhookresponse.text) @@ -173,12 +176,10 @@ def processRequest(req): webhookresponse['active']) + "\n" + " Recovered cases : " + str( webhookresponse['recovered']) + "\n*********" print("***World wide Report*** \n\n" + webhookresponse1 + "\n\n*******END********* \n") - print("***World wide Report*** \n\n" + webhookresponse2 + "\n\n*******END********* \n") - print("***World wide Report*** \n\n" + webhookresponse3 + "\n\n*******END********* \n") - + print("***Country wide Report*** \n\n" + webhookresponse2 + "\n\n*******END********* \n") + print("***State wide Report*** \n\n" + webhookresponse3 + "\n\n*******END********* \n") - - log.saveConversations(sessionID, "Indian State Cases", webhookresponse1, intent, db) + # log.saveConversations(sessionID, "Indian State Cases", webhookresponse1, intent, db) return { "fulfillmentMessages": [ @@ -218,7 +219,6 @@ def processRequest(req): ] } - else: return { "fulfillmentText": "something went wrong,Lets start from the begning, Say Hi", @@ -226,7 +226,8 @@ def processRequest(req): def configureDataBase(): - client = MongoClient("mongodb+srv://username:passwrod@cluster0-replace with you URL.mongodb.net/test?retryWrites=true&w=majority") + client = MongoClient( + "mongodb+srv://Covid_19-Bot:Project_1@Minor@cluster0.jvzhh.mongodb.net/myFirstDatabase?retryWrites=true&w=majority") return client.get_database('covid19DB') @@ -242,14 +243,14 @@ def makeAPIRequest(query): return api.makeApiRequestForCounrty(query) -def prepareEmail(contact_list): - mailclient = EMailClient.GMailClient() - mailclient.sendEmail(contact_list) +# def prepareEmail(contact_list): +# mailclient = EMailClient.GMailClient() +# mailclient.sendEmail(contact_list) if __name__ == '__main__': port = int(os.getenv('PORT')) print("Starting app on port %d" % port) - app.run(debug=False, port=port, host='0.0.0.0') -'''if __name__ == "__main__": - app.run(port=5000, debug=True)''' # running the app on the local machine on port 8000 + app.run(debug=True, port=5000, host='0.0.0.0') +# if __name__ == "__main__": +# app.run(port=5000, debug=True) # running the app on the local machine on port 8000 diff --git a/manifest.yml b/manifest.yml index 7b748c7..dead716 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,7 +1,7 @@ --- applications: -- name: covid_19_bot +- name: MionrCovid_19Bot memory: 2.0GB disk_quota: 2.0GB random-route: true diff --git a/requirement.txt b/requirement.txt new file mode 100644 index 0000000..6fed554 Binary files /dev/null and b/requirement.txt differ diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c99217d..0000000 --- a/requirements.txt +++ /dev/null @@ -1,36 +0,0 @@ -APScheduler==3.6.3 -asn1crypto==1.3.0 -beautifulsoup4==4.8.2 -certifi==2020.4.5.1 -cffi==1.14.0 -chardet==3.0.4 -Click==7.0 -configreader==0.0.6 -cryptography==2.8 -cycler==0.10.0 -dnspython==1.16.0 -Flask==1.1.1 -Flask-Cors==3.0.8 -idna==2.9 -itsdangerous==1.1.0 -Jinja2==2.11.1 -kiwisolver==1.1.0 -MarkupSafe==1.1.1 -psutil==5.7.0 -pycparser==2.20 -pymongo==3.9.0 -pyOpenSSL==19.1.0 -pyparsing==2.4.6 -PySocks==1.7.1 -python-dateutil==2.8.1 -pytz==2019.3 -requests==2.23.0 -six==1.14.0 -soupsieve==2.0 -SQLAlchemy==1.3.13 -tzlocal==2.0.0 -urllib3==1.25.8 -Werkzeug==1.0.1 -win-inet-pton==1.1.0 -wincertstore==0.2 -#winkerberos==0.7.0 diff --git a/runtime.txt b/runtime.txt index 257b314..3338e5c 100644 --- a/runtime.txt +++ b/runtime.txt @@ -1 +1 @@ -python-3.7.6 \ No newline at end of file +python-3.10.4 \ No newline at end of file diff --git a/saveConversation/Conversations.py b/saveConversation/Conversations.py index b7a5fdb..fcb1425 100644 --- a/saveConversation/Conversations.py +++ b/saveConversation/Conversations.py @@ -1,35 +1,37 @@ from datetime import datetime + + class Log: def __init__(self): - pass - - def saveConversations(self, sessionID, usermessage,botmessage,intent,dbConn): + self.current_time = None + self.date = None + self.now = None + def saveConversations(self, sessionID, usermessage, botmessage, intent, dbConn): self.now = datetime.now() self.date = self.now.date() self.current_time = self.now.strftime("%H:%M:%S") - #db = dbConn['Covid-19DB'] # connecting to the database called crawlerD - mydict = {"sessionID":sessionID,"User Intent" : intent ,"User": usermessage, "Bot": botmessage, "Date": str(self.date) + "/" + str(self.current_time)} + # db = dbConn['Covid-19DB'] # connecting to the database called crawlerD + mydict = {"sessionID": sessionID, "User Intent": intent, "User": usermessage, "Bot": botmessage, + "Date": str(self.date) + "/" + str(self.current_time)} - #table = db[sessionID] + # table = db[sessionID] records = dbConn.chat_records records.insert_one(mydict) - #table.insert_one(mydict) + # table.insert_one(mydict) - - def saveCases(self, search,botmessage,dbConn): + def saveCases(self, search, botmessage, dbConn): myquery = {"search": search} - cases_dict = {"search":search,"cases": botmessage} + cases_dict = {"search": search, "cases": botmessage} newvalues = {"$set": cases_dict} records = dbConn.cases_records records.update_one(myquery, newvalues) - #records.insert_one(cases_dict) + # records.insert_one(cases_dict) - def getcasesForEmail(self, search,botmessage,dbConn): + def getcasesForEmail(self, search, botmessage, dbConn): records = dbConn.cases_records return records.find_one({'search': search}) - diff --git a/saveConversation/__pycache__/Conversations.cpython-39.pyc b/saveConversation/__pycache__/Conversations.cpython-39.pyc new file mode 100644 index 0000000..233aaf1 Binary files /dev/null and b/saveConversation/__pycache__/Conversations.cpython-39.pyc differ diff --git a/sendEmail/DLM_Template.html b/sendEmail/DLM_Template.html index 64dc672..c432325 100644 --- a/sendEmail/DLM_Template.html +++ b/sendEmail/DLM_Template.html @@ -1,3 +1,16 @@ + + + + + + + Document + + + + + @@ -43,7 +56,7 @@ src="https://ci4.googleusercontent.com/proxy/qYa6_H461C21RR-qYIwSBcI7qqS9WSiFAN0DaF9sKsbdOZ5S3C-vrr7s_W7pzqFo7qGPHn6zXYPCgzf3sLpi6Csr9HA9gNV6rWRnwUrSjrNGKy8ubI-d=s0-d-e1-ft#https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png" class="CToWUd">  - Covid-19_prevention_measures.pdf + Covid-19_prevention_measures.pdf @@ -351,125 +364,8 @@ -

- - +

@@ -488,7 +384,7 @@
- +
@@ -894,13 +790,13 @@ contact us at  - - raturid33@gmail.com if + navneetguptaend@gmail.com if you need any diff --git a/sendEmail/EMailClient.py b/sendEmail/EMailClient.py index 4b8a679..4520f94 100644 --- a/sendEmail/EMailClient.py +++ b/sendEmail/EMailClient.py @@ -1,20 +1,17 @@ -import os import smtplib -import imghdr from email.message import EmailMessage + from sendEmail import template_reader -from bs4 import BeautifulSoup -import json -import re + class GMailClient: - def sendEmail(self,contacts): - #EMAIL_ADDRESS = os.environ.get('EMAIL_USER') - #EMAIL_PASSWORD = os.environ.get('EMAIL_PASS') - EMAIL_ADDRESS = 'sender email' - EMAIL_PASSWORD = 'sender password' + def sendEmail(self, contacts): + # EMAIL_ADDRESS = os.environ.get('EMAIL_USER') + # EMAIL_PASSWORD = os.environ.get('EMAIL_PASS') + EMAIL_ADDRESS = 'chatbotproject210@gmail.com' + EMAIL_PASSWORD = 'Chatbot_1' - #contacts = ['dineshraturi22@gmail.com'] + # contacts = ['navneetguptaend@gmail.com'] msg = EmailMessage() msg['Subject'] = 'Detailed Covid-19 Report!' @@ -25,10 +22,10 @@ def sendEmail(self,contacts): values = value.get("cases") print(values) msg.set_content("Hello Mr. {} Here is your Covid 19 Report PFA".format(contacts[0])) - #print(contacts[2]) + # print(contacts[2]) template = template_reader.TemplateReader() email_message = template.read_course_template("simple") - #print(email_message) + # print(email_message) country_name1 = "India" total1 = str(values.get("total")) new1 = str(values.get("new")) @@ -36,20 +33,19 @@ def sendEmail(self,contacts): critical1 = str(values.get("critical")) recovered1 = str(values.get("recovered")) print(new1 + total1) - #.format(code1=code1, code2=code2, code3=code3, code4=code4, code5=code5 + # .format(code1=code1, code2=code2, code3=code3, code4=code4, code5=code5 '''msg.add_alternative(email_message.format(country_name=country_name1, total=total1, new=new1, active=active1, critical=critical1, recovered=recovered1,subtype='html'))''' - - - msg.add_alternative(email_message.format(country_name=country_name1, total=total1, new=new1, active=active1, critical=critical1, - recovered=recovered1), subtype='html') - + msg.add_alternative( + email_message.format(country_name=country_name1, total=total1, new=new1, active=active1, critical=critical1, + recovered=recovered1), subtype='html') with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp: smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD) smtp.send_message(msg) - #print("email sent") + print("email sent") + def __init__(self): - pass \ No newline at end of file + pass diff --git a/sendEmail/TestMongo.py b/sendEmail/TestMongo.py index d88a892..969d0dd 100644 --- a/sendEmail/TestMongo.py +++ b/sendEmail/TestMongo.py @@ -11,5 +11,3 @@ records.remove() - - diff --git a/sendEmail/__pycache__/EMailClient.cpython-39.pyc b/sendEmail/__pycache__/EMailClient.cpython-39.pyc new file mode 100644 index 0000000..6a0e56e Binary files /dev/null and b/sendEmail/__pycache__/EMailClient.cpython-39.pyc differ diff --git a/sendEmail/__pycache__/template_reader.cpython-39.pyc b/sendEmail/__pycache__/template_reader.cpython-39.pyc new file mode 100644 index 0000000..9a59e8a Binary files /dev/null and b/sendEmail/__pycache__/template_reader.cpython-39.pyc differ diff --git a/sendEmail/simple.html b/sendEmail/simple.html index b7f32cc..2b0910b 100644 --- a/sendEmail/simple.html +++ b/sendEmail/simple.html @@ -14,7 +14,7 @@ src="https://ci4.googleusercontent.com/proxy/qYa6_H461C21RR-qYIwSBcI7qqS9WSiFAN0DaF9sKsbdOZ5S3C-vrr7s_W7pzqFo7qGPHn6zXYPCgzf3sLpi6Csr9HA9gNV6rWRnwUrSjrNGKy8ubI-d=s0-d-e1-ft#https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png" class="CToWUd">  - Covid-19_prevention_measures.pdf
+ Covid-19_prevention_measures.pdf
Hi,
diff --git a/sendEmail/template_reader.py b/sendEmail/template_reader.py index a67a9f1..08b520a 100644 --- a/sendEmail/template_reader.py +++ b/sendEmail/template_reader.py @@ -2,16 +2,18 @@ class TemplateReader: def __init__(self): pass - def read_course_template(self,course_name): + @staticmethod + def read_course_template(course_name): + global email_message try: - if (course_name=='report'): + if course_name== 'report': email_file = open("sendEmail/graphs.html", "r") email_message = email_file.read() - elif (course_name == 'country'): + elif course_name == 'country': email_file = open("sendEmail/DLM_Template.html", "r") email_message = email_file.read() - elif (course_name == 'simple'): + elif course_name == 'simple': email_file = open("sendEmail/simple.html", "r") email_message = email_file.read() return email_message diff --git a/sendEmail/world.html b/sendEmail/world.html index 64dc672..f1afa65 100644 --- a/sendEmail/world.html +++ b/sendEmail/world.html @@ -43,7 +43,7 @@ src="https://ci4.googleusercontent.com/proxy/qYa6_H461C21RR-qYIwSBcI7qqS9WSiFAN0DaF9sKsbdOZ5S3C-vrr7s_W7pzqFo7qGPHn6zXYPCgzf3sLpi6Csr9HA9gNV6rWRnwUrSjrNGKy8ubI-d=s0-d-e1-ft#https://ssl.gstatic.com/docs/doclist/images/icon_10_generic_list.png" class="CToWUd">  - Covid-19_prevention_measures.pdf + Covid-19_prevention_measures.pdf @@ -351,125 +351,8 @@ -

- - +

@@ -488,7 +371,7 @@
- +