コード例 #1
0
 def updateData(self):
     try:
         dataScrape.getData()
         self.loadStats()
         return ("Data updated successfully Boss Rane")
     except Exception as ex:
         return (ex)
コード例 #2
0
from flask import Flask, request, render_template
from pymessenger.bot import Bot
import random
from dataCleaning import queryingData
import os
import dataScrape, dataCleaning

app = Flask(__name__)
ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
VERIFY_TOKEN = os.environ['VERIFY_TOKEN']

bot = Bot(ACCESS_TOKEN)

dataScrape.getData()
cases = dataCleaning.queryingData().cases
active = dataCleaning.queryingData().active
deaths = dataCleaning.queryingData().deaths
recoveries = dataCleaning.queryingData().recovered
date = dataCleaning.queryingData().dateUpdated
newCases = dataCleaning.queryingData().todayCases
newDeaths = dataCleaning.queryingData().todayDeaths
newRecov = dataCleaning.queryingData().todayRecovered


@app.route('/')
def index():
    return render_template("index.html",
                           cases=cases,
                           active=active,
                           deaths=deaths,
                           recoveries=recoveries,
コード例 #3
0
    def loadJson(self, queryText):
        
        if (queryText.lower() == "admin update data"):
            try:
                dataScrape.getData()
                return("Data updated successfully Boss Rane")  
            except Exception as ex:
                return(ex)

        elif (queryText.lower() == "info"):
            self.info = "Hi this chatbot is created to track statistics of the CoViD-19 pandemic in the Philippines.\n" \
                "Data is from the public API of DOH. However, it may not be up to date with the newest cases that is not yet updated on the DOH's server.\n" \
                    "\nThe chatbot currently supports the following keywords:\n" \
                        "*INFO - to display information regarding this chatbot\n" \
                            "*PH# - to display the details of the person (ex: PH661)\n"\
                            "*PLACE\HOSPITAL - to display current cases in a place or hospital (ex: CAGAYAN or CAGAYAN VALLEY MEDICAL CENTER or CVMC)\n"\
                            "*PUI\n"\
                                "*PUM\n"\
                                    "*CONFIRMED\n"\
                                        "*DEATHS\n"\
                                            "*RECOVERED\n"\
                                                "*TESTS\n"\
                                                    "You can also try to greet, say thanks, and bid goodbye.\n\n"\
                                                        "-Rane 2020"
                                                    

            return (self.info)

        elif re.search(r'^(hi)|^(hello)', queryText.lower()):
            self.response = ["Hi there.", "Hello there", "Good day"]
            return (random.choice(self.response))
        
        elif re.search(r'^(bye)|^(goodbye)', queryText.lower()):
            self.response = ["Bye. Keep Safe and always wash your hands!", "Goodbye! Always keep safe!", "Keep Safe! Keep clean!", "Bye! Stay indoors! Together we fight!"]
            return (random.choice(self.response))

        elif re.search(r'^(thanks)|^(thank)', queryText.lower()):
            self.response = ["No problem. Let's flatten the curve", "You're welcome. Help flatten the curve!", "You're welcome! Stay indoors!"]
            return (random.choice(self.response))

        elif re.search(r'^(pui)', queryText.lower()):#for PUIs
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    #return("There are currently {} PUIs in the Philippines".format(value['PUIs']))
                    return("Sorry the public API offered by DOH before was taken down by DOH. Thus, the chatbot can't offer updated information anymore.")
        
        elif re.search(r'^(pum)', queryText.lower()):#for PUMs
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    #return("There are currently {} PUMs in the Philippines".format(value['PUMs']))
                    return("Sorry the public API offered by DOH before was taken down by DOH. Thus, the chatbot can't offer updated information anymore.")

        elif re.search(r'^(confirmed)|^(confirm)|^(current)', queryText.lower()):#for confirmed cases
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    return("There are currently {} confirmed cases in the Philippines".format(value['confirmed']))

        elif re.search(r'^ph\d+', queryText.lower()): #for PH###
            with open('masterList.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    if (value['PH_masterl'] == queryText.upper()):
                        return ("{}, {}, {}, resident of {} and admitted at {}".format(value['PH_masterl'], value['kasarian'], value['edad'], value['residence'], value['facility']))
            return("{}'s details are not yet available.".format(queryText.lower()))

        if re.search(r'^(recovered)|^(recovery)|^(recover)', queryText.lower()):#for recovered
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    return("There are currently {} recovered in the Philippines".format(value['recovered']))

        if re.search(r'^(death)|^(dead)|^(die)|^(deaths)', queryText.lower()):#for deaths
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    return("There are currently {} deaths in the Philippines".format(value['deaths']))

        if re.search(r'^(test)|^(tested)|^(tests)', queryText.lower()):#for tests
            with open('statistics.json') as file:
                self.data = json.load(file)

            for features in self.data['features']:
                for key, value in features.items():
                    #return("There are currently {} tests conducted in the Philippines".format(value['tests']))
                    return("Sorry the public API offered by DOH before was taken down by DOH. Thus, the chatbot can't offer updated information anymore.")


        else: #for facility or place
            self.response = ""
            with open('facilityStats.json') as file:
                self.data = json.load(file)
            
            with open('locationStats.json') as file:
                self.data2= json.load(file)
            
            
            # queryInitials = queryText.split()
            # for word in queryInitials:
            #     queryInit = queryInit + word[0]
            # queryInitial = ("".join(queryInit).lower())
            
            queryText = queryText.lower()
            regex = r'' + queryText + r''

            for features in self.data2['features']:
                    for key, value in features.items():

                        if re.search(regex, value['residence'].lower()):
                            if (value['value'] == 1):
                                self.response = self.response + ("-{} has {} confirmed case of CoViD-19\n".format(value['residence'], value['value']))
                            else:
                                self.response = self.response + ("-{} has {} confirmed cases of CoViD-19\n".format(value['residence'], value['value']))

            for features in self.data['features']:
                    for key, value in features.items():
                        facilityInitials = ""
                        facilityInit = value['facility'].replace(
                            "and", " ").replace(
                                "for", " ").replace(
                                    "-", " ").replace(
                                        "of", " ").replace(
                                            "in", " ").replace(
                                                "the", " ").split()
                        for word in facilityInit:
                            facilityInitials = facilityInitials + word[0]
                        facilityInitials = ("".join(facilityInitials).lower())

                        if re.search(regex, value['facility'].lower())  or re.search(r'^' + queryText , facilityInitials):
                        
                            if (value['count_'] == 1):
                                self.response = self.response + ("-{} has {} patient with CoViD-19\n".format(value['facility'], value['count_']))
                            else:
                                self.response = self.response + ("-{} has {} patients with CoViD-19\n".format(value['facility'], value['count_']))
                        
            if (self.response == ""):
                unknown = ["Sorry, I dont understand.", "I can't comprehend", "Sorry, please check your keywords"]
                return (random.choice(unknown))
                #return("Sorry the public API offered by DOH before was taken down by DOH. Thus, the chatbot can't offer updated information anymore.")

            else:
                #return(self.response)
                return("Sorry the public API offered by DOH before was taken down by DOH. Thus, the chatbot can't offer updated information anymore.")


#testing
#q = queryingData()
#print(q.loadJson("admin update data"))
コード例 #4
0
def timed_job():
    #print('This job is run every three minutes.')
    dataScrape.getData()
コード例 #5
0
    def loadJson(self, queryText):

        if (queryText.lower() == "admin update data"):
            try:
                dataScrape.getData()
                return ("Data updated successfully Boss Rane")
            except Exception as ex:
                return (ex)

        elif (queryText.lower() == "info"):
            self.info = """Hi this chatbot is created to track statistics of the CoViD-19 pandemic in the Philippines.
Data is from https://coronavirus-ph-api.herokuapp.com/. However, it may not be up to date with the newest cases that is not yet updated on the APIs.
* INFO - to display information regarding this chatbot.
* PH# - to display the details of the person (ex: PH661).
* Location - to display cases in a location (ex: Cagayan).
* HOSPITAL - to display current cases  hospital (ex: CAGAYAN VALLEY MEDICAL CENTER or CVMC).
* CONFIRMED - to display total confirmed cases.
* DEATHS - to display total deaths.
* RECOVERED - to display total recoveries.
* RATES - display recovery and fatality rate.
* FRESH - display fresh cases.
"""

            return (self.info)

        elif re.search(r'^(hi)|^(hello)', queryText.lower()):
            self.response = ["Hi there.", "Hello there", "Good day"]
            return (random.choice(self.response))

        elif re.search(r'^(bye)|^(goodbye)', queryText.lower()):
            self.response = [
                "Bye. Keep Safe and always wash your hands!",
                "Goodbye! Always keep safe!", "Keep Safe! Keep clean!",
                "Bye! Stay indoors! Together we fight!"
            ]
            return (random.choice(self.response))

        elif re.search(r'^(thanks)|^(thank)', queryText.lower()):
            self.response = [
                "No problem. Let's flatten the curve",
                "You're welcome. Help flatten the curve!",
                "You're welcome! Stay indoors!"
            ]
            return (random.choice(self.response))

        elif re.search(r'^(ph)\d+', queryText.lower()):  # for PH###
            FV = "For validation"
            with open('masterList.json') as file:
                self.data = json.load(file)

            for case in self.data['data']:
                if (str(case['case_no'][2:]).lstrip("0") ==
                        queryText[2:].lstrip("0")):
                    if (case['sex'] == FV and case['age'] == FV
                            and case['residence_in_the_ph'] == FV
                            and case['hospital_admitted_to'] == FV
                            and case['date_of_announcement_to_public'] == FV):
                        return ("{}'s details are not yet available".format(
                            queryText.upper()))
                    else:
                        return (
                            "{}, {}, {}, {} nationality from {}, admitted at {}, announced to public on {}, and now with a status of {}"
                            .format(queryText.upper(), case['sex'],
                                    case['age'], case['nationality'],
                                    case['residence_in_the_ph'],
                                    case['hospital_admitted_to'],
                                    case['date_of_announcement_to_public'],
                                    case['health_status']))
コード例 #6
0
    def loadJson(self, queryText):

        if (queryText.lower() == "admin update data"):
            try:
                dataScrape.getData()
                return ("Data updated successfully Boss Rane")
            except Exception as ex:
                return (ex)

        elif (queryText.lower() == "info"):
            self.info = "Hi this chatbot is created to track statistics of the CoViD-19 pandemic in the Philippines.\n" \
                "DOH does not offer any public API as of now. Thus, Data is from https://coronavirus-ph-api.herokuapp.com/ and https://covid19.mathdro.id/. However, it may not be up to date with the newest cases that is not yet updated on the APIs.\n" \
                    "\nThe chatbot currently supports the following keywords:\n" \
                        "*INFO - to display information regarding this chatbot\n" \
                            "*PH# - to display the details of the person (ex: PH661)\n"\
                            "*REGION # - to display cases in a region (ex: REGION II (Use Roman Numerals))\n"\
                            "*HOSPITAL - to display cases in a hospital (ex: CAGAYAN VALLEY MEDICAL CENTER or CVMC)\n"\
                                "*CONFIRMED\n"\
                                    "*DEATHS\n"\
                                        "*RECOVERED\n"\
                                            "You can also try to greet, say thanks, and bid goodbye.\n\n"\
                                                "-Rane 2020"

            return (self.info)

        elif re.search(r'^(hi)|^(hello)', queryText.lower()):
            self.response = ["Hi there.", "Hello there", "Good day"]
            return (random.choice(self.response))

        elif re.search(r'^(bye)|^(goodbye)', queryText.lower()):
            self.response = [
                "Bye. Keep Safe and always wash your hands!",
                "Goodbye! Always keep safe!", "Keep Safe! Keep clean!",
                "Bye! Stay indoors! Together we fight!"
            ]
            return (random.choice(self.response))

        elif re.search(r'^(thanks)|^(thank)', queryText.lower()):
            self.response = [
                "No problem. Let's flatten the curve",
                "You're welcome. Help flatten the curve!",
                "You're welcome! Stay indoors!"
            ]
            return (random.choice(self.response))

        elif re.search(r'^(pui)', queryText.lower()):  #for PUIs
            return (
                "Sorry the public API offered by DOH before was unavailable. Thus, the chatbot can't offer information on the number of PUIs."
            )

        elif re.search(r'^(pum)', queryText.lower()):  #for PUMs
            return (
                "Sorry the public API offered by DOH before was unavailable. Thus, the chatbot can't offer information on the number of PUMs."
            )

        elif re.search(r'^(confirmed)|^(confirm)|^(current)',
                       queryText.lower()):  #for confirmed cases
            with open('statistics.json') as file:
                self.data = json.load(file)

            return ("There are currently {} confirmed cases in the Philippines"
                    .format(self.data['confirmed']['value']))

        elif re.search(r'^ph\d+', queryText.lower()):  #for PH###
            with open('masterList.json') as file:
                self.data = json.load(file)

            for case in self.data:
                if (str(case['case_no']) == queryText.lower()[2:]):
                    if (case['gender'] == "TBA" and case['age'] == "TBA"
                            and case['resident_of'] == "TBA"
                            and case['hospital_admitted_to'] == "TBA"
                            and case['date'] == "TBA"):
                        return ("{}'s details are not yet available".format(
                            queryText.upper()))
                    else:
                        return (
                            "{}, {}, {}, from Region {} and admitted at {} on {}"
                            .format(queryText.upper(), case['gender'],
                                    case['age'], case['resident_of'],
                                    case['hospital_admitted_to'],
                                    case['date']))
            return ("{}'s details are not yet available.".format(
                queryText.upper()))