Exemplo n.º 1
0
 def process_data_for_myanmar(self):
     try:
         a = WikipediaService(url="https://en.wikipedia.org/wiki/2020_coronavirus_pandemic_in_Myanmar")
         country = "Myanmar"
         table_text = "Confirmed COVID-19 cases by Township"
         start_row = "3"
         table = a.search_table(table_text, index=1)
         if start_row.isnumeric():
             table = table[int(start_row) - 1:]
         res = []
         for row in table:
             region = self.get_city_name(row[1], row[2])
             if 'Total' in region:
                 continue
             infected = row[3]
             deaths = row[-1]
             d = dict(
                 region=region,
                 infected=sanitize_digit(infected),
                 deaths=sanitize_digit(deaths),
                 recoveries="0",
             )
             res.append(d)
         file_name = self.get_output_file(country)
         cleanup(file_name)
         self.write_output_for_country(res, country=country, file_name=file_name)
         move_to_final(file_name)
     except Exception as e:
         print(f"Exception fetching myanmar data: {e}")
Exemplo n.º 2
0
 def get_active_for_row(self, row):
     active = row.get("active", "")
     if active:
         return sanitize_digit(active)
     else:
         infected = int(sanitize_digit(row.get("infected", "")))
         deaths = int(sanitize_digit(row.get("deaths", "")))
         recoveries = int(sanitize_digit(row.get("recoveries", "")))
         if deaths > infected or recoveries > infected:
             print(row)
         active = infected - deaths - recoveries
         return str(active)
Exemplo n.º 3
0
 def process_country_table(self, table, country, start_row, end_row,
                           region_col, total_col, death_col, recovered_col,
                           active_col):
     if start_row.isnumeric():
         table = table[int(start_row) - 1:]
     if end_row.lstrip('-+').isnumeric():
         table = table[:int(end_row)]
     result = []
     for row in table:
         region = row[int(region_col) - 1]
         total = deceased = recovered = active = "0"
         if total_col.isnumeric():
             total = row[int(total_col) - 1]
             total = total if total.strip() else "0"
         if active_col.isnumeric():
             active = row[int(active_col) - 1]
             active = active if active.strip() else "0"
         if death_col.isnumeric():
             deceased = row[int(death_col) - 1]
             deceased = deceased if deceased.strip() else "0"
         if recovered_col.isnumeric():
             recovered = row[int(recovered_col) - 1]
             recovered = recovered if recovered.strip() else "0"
         else:
             try:
                 recovered = str(
                     int(sanitize_digit(total)) -
                     int(sanitize_digit(deceased)) -
                     int(sanitize_digit(active)))
             except Exception:
                 print(region, total, deceased, active)
         d = dict(
             country=country,
             region=region,
             infected=total,
             deaths=deceased,
             recoveries=recovered,
             active=active,
             last_updated=self.last_updated.strftime("%Y-%m-%d %H:%M:%S"))
         result.append(d)
     return result
 def get_features_for_row(self,
                          country,
                          region,
                          infected,
                          deaths,
                          recoveries,
                          long,
                          lat,
                          last_updated,
                          active="",
                          total_per_mil="",
                          deaths_per_mil="",
                          total_tests=""):
     if active:
         current = str(active)
     else:
         try:
             current = int(infected) - int(deaths) - int(recoveries)
             current = str(current)
         except Exception as e:
             current = ""
     if lat == "" or long == "":
         lat, long = self.get_lat_long(country, region)
     if not lat:
         return
     point = Point((float(long), float(lat)))
     data_type = "Regional" if region else "National"
     feature = Feature(geometry=point,
                       properties={
                           "Data Type": data_type,
                           "Country": sanitize_text(country),
                           "City": sanitize_text(region),
                           "Current Cases": sanitize_digit(current),
                           "Total Cases": sanitize_digit(infected),
                           "Deceased": sanitize_digit(deaths),
                           "Recovered": sanitize_digit(recoveries),
                           "Total Cases/1M pop":
                           sanitize_digit(total_per_mil),
                           "Deaths/1M pop": sanitize_digit(deaths_per_mil),
                           "Total Tests": sanitize_digit(total_tests),
                           "Last Updated": last_updated
                       })
     return feature
Exemplo n.º 5
0
 def write_output_for_country(self, output, country=None, file_name=None):
     if file_name is None:
         file_name = self.get_output_file("default")
     for row in output:
         if country is None:
             country_str = row.get("country", "")
         else:
             country_str = country
         region = sanitize_text(row.get("region", ""))
         lat, long = self.geojson_service.get_lat_long(country_str, region)
         record = dict(country=sanitize_text(country_str),
                       region=region,
                       infected=sanitize_digit(row.get("infected", "")),
                       deaths=sanitize_digit(row.get("deaths", "")),
                       recoveries=sanitize_digit(row.get("recoveries", "")),
                       long=long,
                       lat=lat,
                       last_updated=self.last_updated.strftime("%Y-%m-%d %H:%M:%S"))
         if country is None:
             record["active"] = sanitize_digit(row.get("active", ""))
             record["total_per_mil"] = sanitize_digit(row.get("total_per_mil", ""))
             record["deaths_per_mil"] = sanitize_digit(row.get("deaths_per_mil", ""))
             record["total_tests"] = sanitize_digit(row.get("total_tests", ""))
             record["active_per_mil"] = sanitize_digit(row.get("active_per_mil", ""))
             record["recovered_per_mil"] = sanitize_digit(row.get("recovered_per_mil", ""))
             record["tests_per_mil"] = sanitize_digit(row.get("tests_per_mil", ""))
             record["new_cases"] = sanitize_digit(row.get("new_cases", ""))
             record["new_deaths"] = sanitize_digit(row.get("new_deaths", ""))
         write_record_to_output(record, file_name)
Exemplo n.º 6
0
 def process_table(self, table, start_row, end_row, country_col, total_col,
                   death_col, recovered_col, active_col, total_per_mil_col,
                   deaths_per_mil_col, total_tests_col, new_cases_col,
                   new_deaths_col, population_col):
     if start_row.isnumeric():
         table = table[int(start_row) - 1:]
     if end_row.lstrip('-+').isnumeric():
         table = table[:int(end_row)]
     result = []
     region = ""
     for row in table:
         try:
             country = row[int(country_col) - 1]
             total = deceased = recovered = active = total_per_mil = total_tests = deaths_per_mil = "0"
             active_per_mil = recovered_per_mil = tests_per_mil = new_cases = new_deaths = pop = "0"
             if total_col.isnumeric():
                 total = row[int(total_col) - 1]
                 total = total if total.strip() else "0"
             if active_col.isnumeric():
                 active = row[int(active_col) - 1]
                 active = active if active.strip() else "0"
             if deaths_per_mil_col.isnumeric():
                 deaths_per_mil = row[int(deaths_per_mil_col) - 1]
                 deaths_per_mil = deaths_per_mil if deaths_per_mil.strip(
                 ) else "0"
             if total_per_mil_col.isnumeric():
                 total_per_mil = row[int(total_per_mil_col) - 1]
                 total_per_mil = total_per_mil if total_per_mil.strip(
                 ) else "0"
             if total_tests_col.isnumeric():
                 total_tests = row[int(total_tests_col) - 1]
                 total_tests = total_tests if total_tests.strip() else "0"
             if death_col.isnumeric():
                 deceased = row[int(death_col) - 1]
                 deceased = deceased if deceased.strip() else "0"
             if recovered_col.isnumeric():
                 recovered = row[int(recovered_col) - 1]
                 recovered = recovered if recovered.strip() else "0"
             if population_col.isnumeric():
                 pop = row[int(population_col) - 1]
                 pop = pop if pop.strip() else "0"
             if pop != "0":
                 population_per_mil = int(sanitize_digit(pop)) / 1000000
                 if population_per_mil > 0:
                     active_per_mil = int(
                         int(sanitize_digit(active)) / population_per_mil)
                     recovered_per_mil = int(
                         int(sanitize_digit(recovered)) /
                         population_per_mil)
                     tests_per_mil = int(
                         int(sanitize_digit(total_tests)) /
                         population_per_mil)
             if new_cases_col.isnumeric():
                 new_cases = row[int(new_cases_col) - 1]
                 new_cases = sanitize_digit(
                     new_cases) if new_cases.strip() else "0"
             if new_deaths_col.isnumeric():
                 new_deaths = row[int(new_deaths_col) - 1]
                 new_deaths = sanitize_digit(
                     new_deaths) if new_deaths.strip() else "0"
             d = dict(country=country,
                      region=region,
                      infected=total,
                      deaths=deceased,
                      recoveries=recovered,
                      active=active,
                      total_per_mil=total_per_mil,
                      deaths_per_mil=deaths_per_mil,
                      total_tests=total_tests,
                      active_per_mil=active_per_mil,
                      recovered_per_mil=recovered_per_mil,
                      tests_per_mil=tests_per_mil,
                      new_cases=new_cases,
                      new_deaths=new_deaths,
                      pop=pop,
                      last_updated=self.last_updated.strftime(
                          "%Y-%m-%d %H:%M:%S"))
             result.append(d)
         except Exception as e:
             print(row, e)
     return result