示例#1
0
def test_dataByName_spaces():
    NewYork1 = covid19_data.dataByName("new york")
    NewYork2 = covid19_data.dataByName("New York")
    NewYork3 = covid19_data.dataByName("NEWYORK")
    data = get_data.get_all_data([total_url, countries_url, states_url])
    assert NewYork1.deaths == data['NewYork'.upper()]['Deaths']
    assert NewYork2.deaths == data['NewYork'.upper()]['Deaths']
    assert NewYork3.deaths == data['NewYork'.upper()]['Deaths']
示例#2
0
def test_dataByName():
    Texas = covid19_data.dataByName("TeXaS")
    Total = covid19_data.dataByName("tOtAl")
    China = covid19_data.dataByName("ChInA")
    data = get_data.get_all_data([total_url, countries_url, states_url])
    assert Total.deaths == data['Total'.upper()]['Deaths']
    assert Texas.deaths == data['Texas'.upper()]['Deaths']
    assert China.deaths == data['China'.upper()]['Deaths']
示例#3
0
def main(message):
	try:
		data = cd.dataByName(f'{message.text}')
	except KeyError:
		bot.send_message(message.chat.id, 'Place not found')
	else:
		bot.send_message(message.chat.id, f'<ins><b>{message.text}</b></ins>\ntotal: {data.cases}, deaths: {data.deaths}, recovered: {data.recovered}', parse_mode='html')
def quote():
    """Get a stock quote."""

    # POST
    if request.method == "POST":

        # Validate form submission
        if not request.form.get("state"):
            return apology("Choose a state")

        # Get stock open, high, low, vol
        chosen_state = request.form.get("state")
        data = covid19_data.dataByNameShort(chosen_state)
        total = covid19_data.dataByName("Total")

        # Deaths, cases and recovered
        deaths = data.deaths
        cases = data.cases
        total_cases = total.cases


        # Display quote
        return render_template("quoted.html", state=chosen_state, deaths=deaths, cases=cases, total_cases=total_cases)

    # GET
    else:
        return render_template("quote.html")
示例#5
0
def home_view(request):
    # Handling Nigeria covid data 
    url = "https://nigeria-covid-19.p.rapidapi.com/api/states"

    nigeria_covid_info = []

    headers = {
        'x-rapidapi-host': "nigeria-covid-19.p.rapidapi.com",
        'x-rapidapi-key': "c1a059f87emsh26a81e2d8d51a85p11018ajsnbbe48df9b6bb"
        }

    response = requests.request("GET", url, headers=headers).json()
    for dict in response:
        dict_info =  {
            "id": dict['id'],
            "State": dict["States"],
            "cases": dict["No_of_cases"],
            "Admitted": dict["No_on_admission"],
            "Discharged": dict["No_discharged"],
            "Death": dict["No_of_deaths"]
        }
        nigeria_covid_info.append(dict_info)

    # Handling user entry data         
    if request.method == "POST":
        form = EnterCountry(request.POST)
        if form.is_valid():
            form.save()
            form = EnterCountry()
    else:
        form = EnterCountry()

    countries = CountryName.objects.all()
    list_data = [] 
    for country in countries: 
        try:
            data = covid19_data.dataByName(country.country_name)
            dict_data = {
                "confirmed_cases": data.confirmed,
                "deaths": data.deaths,
                "active_cases": data.cases,
                "recovered_cases": data.recovered,
                "caller": data.caller,
            }
            list_data.append(dict_data)

        except Exception:
            wrong_entry = CountryName.objects.all().last()
            error_message = messages.error(request, f"Sorry could'nt pull up covid status on {wrong_entry }")
            get_error = CountryName.objects.all().last().delete()

    context = {
            "items": list_data,
            "search_form": form,
            "covid_info": nigeria_covid_info
        }

    return render(request, 'home.html', context)
示例#6
0
def mess(message):
    final_message = ""
    get_message_bot = message.text

    if get_message_bot == "Total":
        total = covid19_data.dataByName("Total")
        final_message = f"Infected: {total.cases}\nDeaths: " + f"{total.deaths}\nRecovered: " + f"{total.recovered}" + f"\nActive Cases: {total.cases - total.deaths - total.recovered}"
        bot.send_message(message.chat.id, final_message, parse_mode='html')

    else:
        try:
            inf = covid19_data.dataByName(f"{get_message_bot}")
            total = covid19_data.dataByName("Total")
            final_message = f"Infected: {inf.cases}\nDeaths: " + f"{inf.deaths}\nRecovered: " + f"{inf.recovered}" + f"\nActive Cases: {inf.cases - inf.deaths - inf.recovered}"
            bot.send_message(message.chat.id, final_message, parse_mode='html')

        except Exception as e:
            print('Exception')
            bot.send_message("No Data found", final_message, parse_mode='html')
示例#7
0
async def covid19(ctx):
    msg = await ctx.send("Collecting information...")
    total = covid19_data.dataByName("Total")
    egypt = covid19_data.dataByName("Egypt")
    usa = covid19_data.dataByName("US")
    canada = covid19_data.dataByName("Canada")
    india = covid19_data.dataByName("India")
    embed = discord.Embed(
        title="COVID 19 OUTBREAK INFORMATION",
        url=
        "https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public",
        description=
        "Coronavirus disease (COVID-19) is an infectious disease caused by a new virus.",
        color=ctx.author.color)
    embed.set_author(
        name="WORLD HEALTH ORGANIZATION",
        icon_url=
        "https://seeklogo.net/wp-content/uploads/2014/11/who-logo-vector.png")
    embed.set_thumbnail(
        url=
        "https://wpcdn.us-east-1.vip.tn-cloud.net/www.abc6.com/content/uploads/2020/03/coronavirus.png"
    )
    embed.add_field(name="CONFIRMED USA \nCASES", value=usa.cases)
    embed.add_field(name="CONFIRMED CANADA \nCASES", value=canada.cases)
    embed.add_field(name="CONFIRMED INDIA \nCASES", value=india.cases)
    embed.add_field(name="CONFIRMED EGYPT \nCASES", value=egypt.cases)
    embed.add_field(name="TOTAL \nCASES", value=total.cases, inline=True)
    embed.add_field(name="TOTAL \n DEATHS", value=total.deaths, inline=True)
    embed.add_field(name="TOTAL \n RECOVERIES",
                    value=total.recovered,
                    inline=True)
    embed.set_image(
        url=
        "https://media1.tenor.com/images/16df5b8e9a9487e7a1cc980d9800f78b/tenor.gif?itemid=16521690"
    )
    embed.timestamp = datetime.datetime.utcnow()
    await ctx.send(embed=embed)
    await msg.delete()
示例#8
0
async def deaths(message, *, country):
    death = covid19_data.dataByName(str(country))
    print(death.deaths)
    mes = str(death.deaths) + " Deaths in " + str(country)
    await message.send(mes)
示例#9
0
async def recoveries(message, *, country):
    recovery = covid19_data.dataByName(str(country))
    print(recovery.recovered)
    mes = str(recovery.recovered) + " recoveries in " + str(country)
    await message.send(mes)
示例#10
0
        link = search_item.get("link")
    print(link)
    await message.channel.send(link)


@location.error
async def missing(message, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await message.send("Please Specify a Location")
    else:
        await message.send("Something Went Wrong")


@client.command()
async def cases(message, *, country):
    case = covid19_data.dataByName(str(country))
    print(case.cases)
    mes = str(case.cases) + " confirmed cases in " + str(country)
    await message.channel.send(mes)


@cases.error
async def eror(message, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await message.send("Please Specify a Location")
    else:
        await message.send("Something Went Wrong")


@client.command()
async def deaths(message, *, country):
示例#11
0
    def calculate(self,
                  cases=None,
                  deaths=None,
                  recovered=None,
                  state_data=None,
                  country_list=None):
        if recovered is None:
            recovered = 0

        if cases and deaths is not None:
            active = (cases - deaths) - recovered
        else:
            active = 1
            cases = 1
            deaths = 1
            recovered = 1

        days = (self.c_timestamp - self.p_timestamp) / 86400
        try:
            dDeaths = round((deaths - self.previous_row.get('Deaths')) / days,
                            0)
            dActive = round((active - self.previous_row.get('Active')) / days,
                            0)
            dRecovered = round(
                (recovered - self.previous_row.get('Recovered')) / days, 0)
            five_recovered = dRecovered
            five_deaths = dDeaths
            dCases = round((cases - self.previous_row.get('Cases')) / days, 0)
            for item in self.all_data[-4:]:
                deltaR = item.get('dRecovered')
                deltaD = item.get('dDeaths')
                if deltaD is None or deltaR is None:
                    five_deaths = 1
                    five_recovered = 0
                else:
                    five_recovered += float(deltaR)
                    five_deaths += float(deltaD)
        except TypeError:
            dDeaths, dActive, dRecovered, five_recovered, dCases = 0, 0, 0, 0, 0
            five_deaths = 1
        except ValueError:
            dDeaths, dActive, dRecovered, five_recovered, dCases = 0, 0, 0, 0, 0
            five_deaths = 1

        headers = {
            "Date": self.c_time,
            "Cases": cases,
            "Deaths": deaths,
            "Recovered": recovered,
            "Active": active,
            "pDeaths": deaths / cases,
            "pRecovered": recovered / cases,
            "pActive": active / cases,
            "R/D": recovered / deaths,
            "Days": days,
            "dCases": dCases,
            "dDeaths": dDeaths,
            "dActive": dActive,
            "dRecovered": dRecovered,
            "5 day heal:death": five_recovered / five_deaths
        }

        sum51 = 0
        if state_data is not None:
            for state in self.state_dict:
                headers.update({state: state_data[state]})
                sum51 += state_data[state]
            headers.update({
                "51 Sum": sum51,
                "51 Sum Diff": abs(cases - sum51),
                "p51 Diff": (1 - (sum51 / cases))
            })
        else:
            pass

        if country_list is not None:
            for country in country_list:
                data = covid19_data.dataByName(country)
                headers.update({country: data.confirmed})
        else:
            pass

        self.all_data.append(headers)
        return headers
示例#12
0
import covid19_data

# example of how to get data by name
# .dataByName([string of item you want to find, can be any state, country, or total amount (spacing and capitalization do not matter)])
# object has three useful attributes: .deaths, .cases (.confirmed also works), and .recovered

total = covid19_data.dataByName("Total")  # create an object for our total data
china = covid19_data.dataByName("China")
US = covid19_data.dataByName("US")
new_york = covid19_data.dataByName("NewYork")
print(total.deaths, china.recovered, US.cases)

# example of how to get data by abbreviated name
# .dataByNameShort([two letter string of item you want to find, can be any state (spacing and capitalization do not matter)])
# object has three useful attributes: .deaths, .cases (.confirmed also works), and .recovered

texas = covid19_data.dataByNameShort(
    "TX")  # create an object for our total data
california = covid19_data.dataByNameShort("CA")
new_york = covid19_data.dataByNameShort("NY")
print(texas.cases, california.deaths, new_york.cases)