From f93ee4a9672cb3d1318a51508f545f5ff70427a4 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 26 Oct 2023 08:50:18 -0700 Subject: [PATCH] Removing corona and pandas install. shoudl speed up build times significantly --- .pre-commit-config.yaml | 6 ++ app/corona.py | 145 ---------------------------------------- app/requirements.txt | 2 +- 3 files changed, 7 insertions(+), 146 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100755 app/corona.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..54db4d5d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,6 @@ +repos: +- repo: https://github.com/ambv/black + rev: 23.10.1 + hooks: + - id: black + language_version: python3.11.6 diff --git a/app/corona.py b/app/corona.py deleted file mode 100755 index 41f9138b..00000000 --- a/app/corona.py +++ /dev/null @@ -1,145 +0,0 @@ -from pandas import read_csv -import discord -import os -import pandas as pd -import requests -import string -import datetime - - -def get_csv(): - git_url = "https://api.github.com/repos/CSSEGISandData/COVID-19/contents/csse_covid_19_data/csse_covid_19_daily_reports" - git_blob = requests.get(git_url).json() - - today = datetime.datetime.utcnow().date() - todays_date = today.strftime("%m-%d-%Y") - yesterday = today - datetime.timedelta(days=1) - yesterdays_date = yesterday.strftime("%m-%d-%Y") - - most_recent = next(filter(lambda x: yesterdays_date in x["name"], git_blob)) - file_name = most_recent["name"] - download_url = most_recent["download_url"] - most_recent_csv = "/app/%s" % file_name - if not os.path.exists(most_recent_csv): - print("no local csv found, downloading %s" % file_name) - r = requests.get(download_url, allow_redirects=True) - open(most_recent_csv, "wb").write(r.content) - - two_days_ago = today - datetime.timedelta(days=2) - two_days_ago_date = two_days_ago.strftime("%m-%d-%Y") - yesterday_object = next(filter(lambda x: two_days_ago_date in x["name"], git_blob)) - yesterday_filename = yesterday_object["name"] - yesterday_url = yesterday_object["download_url"] - yesterday_csv = "/app/%s" % yesterday_filename - - if not os.path.exists(yesterday_csv): - print("no local csv found, downloading %s" % yesterday_filename) - r = requests.get(yesterday_url, allow_redirects=True) - open(yesterday_csv, "wb").write(r.content) - - return most_recent_csv, yesterday_csv - - -def query_csv(csv_path, location): - series = read_csv(csv_path, header=0, parse_dates=[0], index_col=0, squeeze=True) - last_updated = series["Last_Update"].iloc[0] - location_query = series.loc[series["Province_State"] == location] - if location_query.empty: - location_query = series.loc[series["Country_Region"] == location] - if location_query.empty: - embed = discord.Embed( - description="No results found for %s.\n\nPlease enter a valid Country name or US state" - % location, - color=0x428BCA, - type="rich", - ) - embed.set_author( - name="CSSE at Johns Hopkins University", - icon_url="https://www.pngitem.com/pimgs/m/27-270528_johns-hopkins-was-a-founding-member-of-the.png", - ) - return embed - return last_updated, location_query.sum() - - -def sum_numbers(location): - today, yesterday = get_csv() - try: - last_updated, yesterday_sum = query_csv(yesterday, location) - last_updated, today_sum = query_csv(today, location) - except TypeError: - return discord.Embed( - description="No data for %s. Did you make a typo?" % location, - color=0x428BCA, - type="rich", - ) - - confirmed = "%s (+%s from yesterday)" % ( - today_sum["Confirmed"], - int(today_sum["Confirmed"]) - int(yesterday_sum["Confirmed"]), - ) - deaths = "%s (+%s from yesterday)" % ( - today_sum["Deaths"], - int(today_sum["Deaths"]) - int(yesterday_sum["Deaths"]), - ) - recovered = "%s (+%s from yesterday)" % ( - today_sum["Recovered"], - int(today_sum["Recovered"]) - int(yesterday_sum["Recovered"]), - ) - - embed = discord.Embed( - description="Most recent Covid19 stats for %s\nUpdated once a day\n(Last update was %s)" - % (location, last_updated), - color=0x428BCA, - type="rich", - ) - embed.set_author( - name="CSSE at Johns Hopkins University", - icon_url="https://www.pngitem.com/pimgs/m/27-270528_johns-hopkins-was-a-founding-member-of-the.png", - ) - embed.add_field( - name=":rotating_light: Confirmed Cases :rotating_light:", - value=confirmed, - inline=False, - ) - embed.add_field( - name=":hospital: Recovered Cases :hospital:", value=recovered, inline=False - ) - embed.add_field( - name=":skull_crossbones: Deaths :skull_crossbones:", value=deaths, inline=False - ) - # if 'Not available' not in get_vaccination_data(location): - # embed.add_field(name=':sparkles: :syringe: Percent vaccinated :syringe: :sparkles:', value=get_vaccination_data(location) + "\nVaccination numbers pulled from\nhttps://covidvaxcount.live", inline=False) - embed.add_field(name="Source", value="https://github.com/CSSEGISandData/COVID-19") - - return embed - - -# def get_vaccination_data(location): -# url = requests.get('https://covidvaxcount.live') -# soup = BeautifulSoup(url.content, features="html.parser") - -# data = [] -# table = soup.find("div", {"class": 'table-responsive'}) -# table_body = table.find('tbody') - -# rows = table_body.find_all('tr') -# for row in rows: -# cols = row.find_all('td') -# cols = [ele.text.strip() for ele in cols] -# data.append([ele for ele in cols if ele]) # Get rid of empty values - -# try: -# state_name, num_vaccinated, population, percent_vaccinated = list(filter(lambda x: x[0] == location, data))[0] -# except Exception: -# return "Not available for %s" % location -# return percent_vaccinated - - -def parse_message(location=None): - try: - location = string.capwords(" ".join(location.split())) - if not location: - location = "California" - except (IndexError, AttributeError): - location = "California" - return sum_numbers(location) diff --git a/app/requirements.txt b/app/requirements.txt index 2cdb1ed5..60f80c8f 100755 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -8,7 +8,7 @@ lxml markovify openai owotext -pandas +pre-commit requests requests-cache wolframalpha