Last active
April 18, 2020 04:25
-
-
Save mrcreel/f644ee0dfe0a9c8d7f87fb59e2e2aca3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
See comments from https://gist.github.com/mrcreel/5432787a57b131a87c3f1724b1f7fffd | |
""" | |
import csv | |
import requests | |
from bs4 import BeautifulSoup | |
URL = 'https://msdh.ms.gov/msdhsite/_static/14,0,420.html' | |
page = requests.get(URL) | |
soup = BeautifulSoup(page.content, 'html.parser') | |
cases = soup.find(id='msdhTotalCovid-19CasesByRace') | |
counties = cases.find_all('tr') | |
counties_totals = [] | |
for county in counties: | |
data = county.find_all('td') | |
county_name = data[0].text | |
if (county_name != 'County' and county_name != 'Total'): | |
county_cases = data[1].text | |
if (county_cases == ' '): | |
county_cases = 0 | |
county_black = data[2].text | |
if (county_black == ' '): | |
county_black = 0 | |
county_white = data[3].text | |
if (county_white == ' '): | |
county_white = 0 | |
county_other = data[4].text | |
if (county_other == ' '): | |
county_other = 0 | |
county_unknown = data[5].text | |
if (county_unknown == ' '): | |
county_unknown = 0 | |
county_data = [county_name, int(county_cases), int( | |
county_black), int(county_white), int(county_other), int(county_unknown)] | |
counties_totals.append(county_data) | |
# Extremely janky code to test if issaquena if it's still at 0 cases | |
# and if so, add it | |
# Set default that issaquena is still 0 | |
issaquena_test = False | |
# test each county to check | |
for row in counties_totals: | |
# if issaquena exists, set to tru | |
if (row[0] == 'Issaquena'): | |
issaquena_test = True | |
# if it still doesn't add it and sort list | |
if(issaquena_test == False): | |
counties_totals.append(['Issaquena', 0, 0, 0, 0, 0]) | |
counties_totals.sort(key=lambda x: x[0]) | |
print(counties_totals) | |
# Write to csv | |
with open("out_racial.csv", "w", newline="") as f: | |
writer = csv.writer(f) | |
writer.writerows(counties_totals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adams,73,37,20,13,3 | |
Alcorn,7,1,5,1,0 | |
Amite,17,9,6,1,1 | |
Attala,31,15,10,2,4 | |
Benton,6,4,2,0,0 | |
Bolivar,76,52,13,3,8 | |
Calhoun,32,11,19,0,2 | |
Carroll,10,6,4,0,0 | |
Chickasaw,39,17,13,7,2 | |
Choctaw,11,4,6,0,1 | |
Claiborne,8,4,2,1,1 | |
Clarke,21,8,11,2,0 | |
Clay,22,19,2,1,0 | |
Coahoma,45,41,2,1,1 | |
Copiah,40,21,7,12,0 | |
Covington,22,11,7,0,4 | |
Desoto,213,83,104,15,11 | |
Forrest,137,59,55,11,12 | |
Franklin,14,8,3,1,2 | |
George,9,0,9,0,0 | |
Greene,3,0,3,0,0 | |
Grenada,15,10,4,0,1 | |
Hancock,50,12,37,1,0 | |
Harrison,137,48,77,7,5 | |
Hinds,314,238,43,27,6 | |
Holmes,54,47,1,3,3 | |
Humphreys,12,9,2,1,0 | |
Issaquena,0,0,0,0,0 | |
Itawamba,13,5,6,0,2 | |
Jackson,196,97,83,12,4 | |
Jasper,20,12,4,2,2 | |
Jefferson,4,3,1,0,0 | |
Jefferson Davis,8,6,1,0,1 | |
Jones,56,20,19,14,3 | |
Kemper,16,14,1,0,1 | |
Lafayette,39,14,19,2,4 | |
Lamar,57,26,21,5,5 | |
Lauderdale,181,126,43,7,5 | |
Lawrence,12,4,5,2,1 | |
Leake,60,37,6,8,9 | |
Lee,49,22,22,3,2 | |
Leflore,70,58,6,3,3 | |
Lincoln,95,30,49,5,11 | |
Lowndes,30,20,6,0,4 | |
Madison,123,51,43,20,9 | |
Marion,38,12,21,3,2 | |
Marshall,37,17,18,1,1 | |
Monroe,58,15,31,2,10 | |
Montgomery,15,10,4,1,0 | |
Neshoba,46,25,13,7,1 | |
Newton,19,11,4,1,3 | |
Noxubee,20,14,4,0,2 | |
Oktibbeha,42,20,12,4,6 | |
Panola,27,22,3,0,2 | |
Pearl River,115,40,52,11,12 | |
Perry,21,5,16,0,0 | |
Pike,93,59,11,6,17 | |
Pontotoc,17,11,5,0,1 | |
Prentiss,16,0,13,3,0 | |
Quitman,13,11,2,0,0 | |
Rankin,128,30,81,12,5 | |
Scott,96,48,24,13,11 | |
Sharkey,3,1,1,1,0 | |
Simpson,14,4,6,1,3 | |
Smith,38,12,22,1,3 | |
Stone,17,4,11,1,1 | |
Sunflower,45,39,3,2,1 | |
Tallahatchie,8,8,0,0,0 | |
Tate,27,9,18,0,0 | |
Tippah,45,28,13,3,1 | |
Tishomingo,2,1,1,0,0 | |
Tunica,28,16,7,1,4 | |
Union,9,5,1,1,2 | |
Walthall,22,11,9,0,2 | |
Warren,17,10,6,0,1 | |
Washington,68,54,7,4,3 | |
Wayne,10,6,2,2,0 | |
Webster,17,10,6,0,1 | |
Wilkinson,53,47,1,3,2 | |
Winston,27,16,9,1,1 | |
Yalobusha,14,7,5,1,1 | |
Yazoo,81,48,26,4,3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment