Skip to content

Commit

Permalink
Ported epi-cli into bin/
Browse files Browse the repository at this point in the history
 - Adds all basic functions
 - Adds CLI functionality to the epispot package
 Note: requires fire to run
       install via `pip install fire`
       or `conda install fire`
  • Loading branch information
quantum9Innovation committed Mar 14, 2021
1 parent b67af12 commit 9ad7cc4
Show file tree
Hide file tree
Showing 5 changed files with 603 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Command-line Interface
Ported from epispot/cli
___
This part of epispot is currently being ported from epispot/cli \
Current development status: **in progress**
110 changes: 110 additions & 0 deletions bin/covid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from bs4 import BeautifulSoup
import requests
import re

if __name__ != "__main__":
all_cases = []
country_cases = []
continent_cases = []
last_updated_val = ""

# Getting the data from https://www.worldometers.info/coronavirus/ via web scraping.
source = requests.get("https://www.worldometers.info/coronavirus/").text
soup = BeautifulSoup(source, "lxml")

# Get last updated date
for page_top in soup.find_all("div", id="page-top"):
last_updated = page_top.find_next_sibling("div")
last_updated_val = last_updated.text.strip("Last updated: ")

# Getting the cases and then added to all_cases list of dictionary
th_row = []
table = soup.table
table_rows = table.find_all("tr")
for tr in table_rows:
th = tr.find_all("th")
td = tr.find_all("td")
if th:
for i in th:
th_text = i.text
if re.search("Country", th_text):
th_row.append("CountryOrRegion")
elif re.search("Critical", th_text):
th_row.append("Critical")
elif re.search("Cases/", th_text):
th_row.append("CasesPerOneMillion")
elif re.search("Deaths/", th_text):
th_row.append("DeathsPerOneMillion")
elif re.search("Tests/", th_text):
th_row.append("TestsPerOneMillion")
else:
th_row.append(th_text)
th_row.append("LastUpdated")
if td:
td_row = [j.text.strip() for j in td]
td_row.append(last_updated_val)
table_dict = dict(zip(th_row, td_row))
all_cases.append(table_dict)

# Filtering the list and create new list just for the Coutries and Continents
region_remover = ["World", "Asia", "North America", "Europe",
"South America", "Oceania", "Africa", "Total:", ""]
regions = ["Asia", "North America", "Europe",
"South America", "Oceania", "Africa"]

for search in all_cases:
if search["CountryOrRegion"] not in region_remover:
country_cases.append(search)
if search["CountryOrRegion"] in regions:
continent_cases.append(search)

# Methods
def get_global_cases():
"""
Returns a dictionary of global cases
"""
result = None
for search in all_cases:
if search["CountryOrRegion"] == "World":
result = search
return result

def get_country_cases(country=None):
"""
Returns a dictionary for sepecific country or list of dictionaries for all coutries.
Parameter:
country = Name of a Country that has COVID-19 case. Will return None if country is not available.
"""
result = None
if country:
if not type(country) is str:
raise TypeError("Parameter is not a string!")
else:
if country.upper() == "South Korea".upper():
country = "S. Korea".upper()
for country_search in country_cases:
if country_search["CountryOrRegion"].upper() == country.upper():
result = country_search
return result
else:
return country_cases

def get_continent_cases(continent=None):
"""
Returns a dictionary for sepecific continent or list of dictionaries for all continents.
Parameter:
continent = Name of the continent that has COVID-19 case. Will return None if continent is not available.
"""
result = None
if continent:
if not type(continent) is str:
raise TypeError("Parameter is not a string!")
else:
for continent_search in continent_cases:
if continent_search["Continent"].upper() == continent.upper():
result = continent_search
return result
else:
return continent_cases
232 changes: 232 additions & 0 deletions bin/data/list-of-countries.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
Zimbabwe
Zambia
Yemen
World
Western Sahara
Wallis and Futuna
Vietnam
Venezuela
Vatican City
Vanuatu
Uzbekistan
USA
Uruguay
Ukraine
UK
Uganda
UAE
Turks and Caicos
Turkey
Tunisia
Trinidad and Tobago
Togo
Timor-Leste
Thailand
Tanzania
Tajikistan
Taiwan
Syria
Switzerland
Sweden
Suriname
Sudan
St. Vincent Grenadines
St. Barth
Sri Lanka
Spain
South Sudan
South Africa
Somalia
Solomon Islands
Slovenia
Slovakia
Sint Maarten
Singapore
Sierra Leone
Seychelles
Serbia
Senegal
Saudi Arabia
Sao Tome and Principe
San Marino
Samoa
Saint Pierre Miquelon
Saint Martin
Saint Lucia
Saint Kitts and Nevis
S. Korea
Réunion
Rwanda
Russia
Romania
Qatar
Portugal
Poland
Philippines
Peru
Paraguay
Papua New Guinea
Panama
Palestine
Pakistan
Oman
Norway
North Macedonia
Nigeria
Niger
Nicaragua
New Zealand
New Caledonia
Netherlands
Nepal
Namibia
Myanmar
MS Zaandam
Mozambique
Morocco
Montserrat
Montenegro
Mongolia
Monaco
Moldova
Micronesia
Mexico
Mayotte
Mauritius
Mauritania
Martinique
Marshall Islands
Malta
Mali
Maldives
Malaysia
Malawi
Madagascar
Macao
Luxembourg
Lithuania
Liechtenstein
Libya
Liberia
Lesotho
Lebanon
Latvia
Laos
Kyrgyzstan
Kuwait
Kenya
Kazakhstan
Jordan
Japan
Jamaica
Ivory Coast
Italy
Israel
Isle of Man
Ireland
Iraq
Iran
Indonesia
India
Iceland
Hungary
Hong Kong
Honduras
Haiti
Guyana
Guinea-Bissau
Guinea
Guatemala
Guadeloupe
Grenada
Greenland
Greece
Gibraltar
Ghana
Germany
Georgia
Gambia
Gabon
French Polynesia
French Guiana
France
Finland
Fiji
Falkland Islands
Faeroe Islands
Ethiopia
Eswatini
Estonia
Eritrea
Equatorial Guinea
El Salvador
Egypt
Ecuador
DRC
Dominican Republic
Dominica
Djibouti
Diamond Princess
Denmark
Czechia
Cyprus
Curaçao
Cuba
Croatia
Costa Rica
Congo
Comoros
Colombia
China
Chile
Channel Islands
Chad
Cayman Islands
Caribbean Netherlands
CAR
Canada
Cameroon
Cambodia
Cabo Verde
Burundi
Burkina Faso
Bulgaria
Brunei
British Virgin Islands
Brazil
Botswana
Bosnia and Herzegovina
Bolivia
Bhutan
Bermuda
Benin
Belize
Belgium
Belarus
Barbados
Bangladesh
Bahrain
Bahamas
Azerbaijan
Austria
Australia
Aruba
Armenia
Argentina
Antigua and Barbuda
Anguilla
Angola
Andorra
Algeria
Albania
Afghanistan
The Arctic
The Caribbean
The Mediterranean
Eastern Europe
The Sahara
North Africa
The Horn of Africa
The Middle East
Southeast Asia
The Tundra
10 changes: 10 additions & 0 deletions bin/data/regions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The Arctic,Denmark,Norway,Sweden,Finland,Russia,Canada,Iceland
The Caribbean,Bahamas,Barbados,Belize,Dominican Republic,Guyana,Haiti,Jamaica,Antigua and Barbuda,Trinidad and Tobago
The Mediterranean,Portugal,Spain,Italy,Greece,Turkey,Morocco,Algeria,Tunisia,Libya,Egypt
Eastern Europe,Finland,Belarus,Ukraine,Romania,Bulgaria,Latvia,Lithuania
The Sahara,Algeria,Libya,Egypt,Mauritiania,Mali,Niger,Chad,Sudan,South Sudan
North Africa,Algeria,Libya,Egypt,Mauritiania,Mali,Niger,Chad,Sudan,South Sudan
The Horn of Africa,Eritrea,Ethiopia,Djibouti,Somalia,Kenya,Sudan,South Sudan
The Middle East,Yemen,Oman,Saudi Arabia,Iraq,Syria,Jordan,Israel
Southeast Asia,Myanmar,Thailand,Cambodia,Vietnam,Laos
The Tundra,Denmark,Norway,Sweden,Finland,Russia,Canada,Iceland

0 comments on commit 9ad7cc4

Please sign in to comment.