Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
#57 #52 Semi-Automatic Honduras
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodz committed Apr 8, 2020
1 parent 1b39430 commit c303c06
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
49 changes: 49 additions & 0 deletions utils/scripts/honduras_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from bs4 import BeautifulSoup
import urllib.request as urllib
import ssl
import json
import numpy as np
import pandas as pd
from datetime import date

"""
Variables a cambiar
"""
# Scraping
webpage = 'http://covid19honduras.org/dll/ODEPTO.php'

# ISO Code
default_columns = ['Number', 'Subdivision',
'ISO 3166-2 Code', 'Confirmed', 'Death', 'Recovered']
reorder_columns = ['ISO 3166-2 Code', 'Subdivision',
'Country', 'Last Update', 'Confirmed', 'Death', 'Recovered']


if __name__ == "__main__":
"""
SCRAP DATA
"""
print("We're going to scrap Honduras reports to create a pandas dataframe")
# Creamos conexión SSL necesaria
context = ssl._create_unverified_context()
web = urllib.urlopen(webpage, context=context)
soup = BeautifulSoup(web)
clean_json = json.loads(str(soup))
# to create a pandas dataframe with the data
dataset = pd.DataFrame(clean_json)
# Naming columns
dataset.columns = default_columns
dataset['Country'] = 'Honduras'
dataset['Last Update'] = date.today()
print(dataset)

# Reorder columns
dataset = dataset.reindex(columns=reorder_columns)
print(dataset)

"""
CHANGE REPOSITORY FAILS
WARNING: TO_CSV TEMPORAL
"""
dataset.to_csv(
"utils/scripts/honduras_temporal/{}.csv".format(date.today()), sep=',', index=False)
12 changes: 12 additions & 0 deletions utils/scripts/honduras_temporal/2020-04-07.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
,ISO 3166-2 Code,Subdivision,Country,Last Update,Confirmed,Death,Recovered
0,HN-AT,Atlántida,Honduras,2020-04-07,16,1,1
1,HN-CH,Choluteca,Honduras,2020-04-07,2,0,0
2,HN-CL,Colón,Honduras,2020-04-07,20,1,0
3,HN-CM,Comayagua,Honduras,2020-04-07,2,0,0
4,HN-CP,Copán,Honduras,2020-04-07,1,0,0
5,HN-CR,Cortés,Honduras,2020-04-07,195,15,0
6,HN-FM,Francisco Morazán,Honduras,2020-04-07,54,2,5
7,HN-LP,La Paz,Honduras,2020-04-07,1,0,0
8,HN-LM,Lempira,Honduras,2020-04-07,4,1,0
9,HN-SB,Santa Bárbara,Honduras,2020-04-07,8,0,0
10,HN-YO,Yoro,Honduras,2020-04-07,9,2,0

0 comments on commit c303c06

Please sign in to comment.