项目作者: kandarpkakkad

项目描述 :
Retrieves Covid-19 Updates from api.covid19india.org API and creates excel sheet for state and district wise timeline data
高级语言: Python
项目地址: git://github.com/kandarpkakkad/Covid19-Data-Extractor-WHO.git
创建时间: 2020-10-08T05:33:53Z
项目社区:https://github.com/kandarpkakkad/Covid19-Data-Extractor-WHO

开源协议:GNU General Public License v3.0

下载


Covid19-Data-Extractor-WHO

  1. Retrieves Covid-19 Updates from api.covid19india.org API and creates excel sheet for state and district wise timeline data

Introduction

This is a personal project to help people to get data automatically. You need to select the state from the dropdown and click on submit. You will get an excel sheet for downloading and that will contain the data of the state selected and all the districts, if any, in that state in different sheets in the file.

The data is extracted from https://www.covid19india.org. This website has its own API, https://api.covid19india.org. The API contains state-wise, district-wise and whole country’s COVID19 data with dates. The excel sheet is generated using this data.

Techonology

The project uses Flask for backend and Jinja2 templates for frontend. XlsxWriter library is used to write in excel file.

Flask

  1. from flask import Flask, render_template, request, send_from_directory
  2. import xlsxwriter as xl
  3. import pandas as pd

We extract the district data and state data using the utility functions below

  1. def extract(state: str) -> (pd.DataFrame, list):
  2. """
  3. :param state: Name of the state for extraction of the data for the state
  4. Getting data of respective state and its districts date wise.
  5. :return: Dataframe of data of respective state
  6. """
  7. global unknowns
  8. try:
  9. assert isinstance(state, str)
  10. except AssertionError as _:
  11. print("String Needed")
  12. raise
  13. print("Reading Data for districts of {}".format(state))
  14. # Read CSV file from covid19india API
  15. if state in unknowns:
  16. data_districts = pd.read_csv("https://api.covid19india.org/csv/latest/districts.csv", header=None, usecols=[0, 1, 3, 4, 5, 7], low_memory=False)
  17. else:
  18. data_districts = pd.read_csv("https://api.covid19india.org/csv/latest/districts.csv", header=None, usecols=[0, 1, 2, 3, 4, 5, 7], low_memory=False)
  19. # Get data of respective state
  20. data_districts_state = data_districts.loc[(data_districts[1] == state)]
  21. districts = []
  22. if state not in unknowns:
  23. districts = data_districts_state[2].unique()
  24. districts.sort()
  25. return data_districts_state, districts
  26. def extract_state_data(state: str) -> pd.DataFrame:
  27. """
  28. :param state: Name of the state for extraction of the data for the state
  29. Getting data of respective state date wise.
  30. :return: Dataframe of data of respective state
  31. """
  32. try:
  33. assert isinstance(state, str)
  34. except AssertionError as _:
  35. print("String Needed")
  36. raise
  37. print("Reading Data for {}".format(state))
  38. data = pd.read_csv("https://api.covid19india.org/csv/latest/states.csv", header=None, usecols=[0, 1, 2, 3, 4, 6], low_memory=False)
  39. return data

Run on local machine

Clone the github repository on local machine

  1. git clone https://github.com/kandarpkakkad/Covid19-Data-Extractor-WHO.git
  2. cd Covid19-Data-Extractor-WHO

Install the requirements

  1. pip3 install -r requirements.txt

Run the flask app

  1. python3 run extract_covid_data.py

Output

Home Page

Home

About Page

About

Contact Page

Contact