### Application Initialization and Server Setup (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt Initializes the Flask application and sets up the database. It ensures all necessary database tables are created before starting the Flask development server. The application uses a MySQL database configured for COVID-19 statistics, creating tables for countries, cases, recoveries, and deaths. Requires 'app' and 'db' from the application's main module. ```python from app import app, db # Initialize database tables and start the Flask server if __name__ == "__main__": db.create_all() # Creates all tables if they don't exist app.run(debug=True, port=4555) # Database configuration (from app/__init__.py) # MySQL connection: mysql://root:root@localhost:3306/coronavirus # Tables created: pais, casos, recuperados, mortes # Plus association tables: pais_casos, pais_recuperados, pais_mortes ``` -------------------------------- ### Get All Cases Worldwide Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of confirmed COVID-19 cases across all countries and a list of all tracked countries. ```APIDOC ## GET /cases ### Description Returns the total number of confirmed COVID-19 cases across all countries along with a list of all tracked countries. ### Method GET ### Endpoint /cases ### Response #### Success Response (200) - **countries** (array of strings) - A list of country names. - **totalQuantity** (integer) - The total number of confirmed cases worldwide. #### Response Example ```json { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 150234567 } ``` ``` -------------------------------- ### Get Cases by Country Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of confirmed COVID-19 cases for a specific country. ```APIDOC ## GET /cases/{country} ### Description Returns the total number of confirmed cases for a specific country. ### Method GET ### Endpoint /cases/{country} ### Parameters #### Path Parameters - **country** (string) - Required - The name of the country to retrieve data for. ### Response #### Success Response (200) - **country** (string) - The name of the country. - **totalQuantity** (integer) - The total number of confirmed cases for the specified country. #### Response Example ```json { "country": "Brazil", "totalQuantity": 12345678 } ``` #### Error Response (400) - **error** (string) - "400" indicating the country was not found. #### Error Response Example ```json { "error": "400" } ``` ``` -------------------------------- ### Get All COVID-19 Cases Worldwide (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of confirmed COVID-19 cases across all countries worldwide, along with a list of all tracked countries. This endpoint is useful for an overall summary of global infection rates. ```bash curl -X GET http://localhost:4555/cases # Response { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 150234567 } ``` -------------------------------- ### Get Statistics by Date and Country Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves specific statistics (cases, recovered, or deaths) for a given country on a specific date. ```APIDOC ## GET /date/{statistic_type}/{country}/{date} ### Description Returns specific statistics (cases, recovered, or deaths) for a given country on a specific date. ### Method GET ### Endpoint /date/{statistic_type}/{country}/{date} ### Parameters #### Path Parameters - **statistic_type** (string) - Required - The type of statistic to retrieve. Accepts 'casos', 'recuperados', or 'mortes'. - **country** (string) - Required - The name of the country to retrieve data for. - **date** (string) - Required - The date in MM-DD-YY format. ### Response #### Success Response (200) - **country** (string) - The name of the country. - **data** (string) - The date of the statistics in ISO 8601 format (YYYY-MM-DDTHH:MM:SS). - **count** (integer) - The number of statistics for the specified type, country, and date. #### Response Example (Cases) ```json { "country": "Brazil", "data": "2021-03-15T00:00:00", "count": 11693838 } ``` #### Response Example (Recovered) ```json { "country": "India", "data": "2021-05-20T00:00:00", "count": 8765432 } ``` #### Response Example (Deaths) ```json { "country": "US", "data": "2021-01-10T00:00:00", "count": 234567 } ``` #### Error Response (400) - **error** (string) - "400" indicating invalid parameters. #### Error Response Example ```json { "error": "400" } ``` ``` -------------------------------- ### Country Model (Pais) Definition and Usage (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt Defines the 'Pais' (Country) model in Python using SQLAlchemy for representing country entities and their relationships to COVID-19 statistics (cases, recoveries, deaths). Includes examples for creating new country entries and querying a country with its related case data. ```python from app.model import Pais, Casos, Recuperados, Mortes from app import db # Create a new country entry novo_pais = Pais(nome_pais="Germany") db.session.add(novo_pais) db.session.commit() # Query a country with its related cases pais = Pais.query.filter_by(nome_pais="Brazil").first() casos_relacionados = pais.pais_caso_relationship for caso in casos_relacionados: print(f"Date: {caso.data}, Cases: {caso.quantidade}") ``` -------------------------------- ### Get All COVID-19 Deaths Worldwide (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of COVID-19 deaths across all countries worldwide, along with a list of all tracked countries. This endpoint offers a global perspective on mortality rates. ```bash curl -X GET http://localhost:4555/deaths # Response { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 3456789 } ``` -------------------------------- ### Get Deaths by Country Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of COVID-19 deaths for a specific country. ```APIDOC ## GET /deaths/{country} ### Description Returns the total number of deaths for a specific country. ### Method GET ### Endpoint /deaths/{country} ### Parameters #### Path Parameters - **country** (string) - Required - The name of the country to retrieve data for. ### Response #### Success Response (200) - **country** (string) - The name of the country. - **totalQuantity** (integer) - The total number of deaths for the specified country. #### Response Example ```json { "country": "US", "totalQuantity": 567890 } ``` #### Error Response (400) - **error** (string) - "400" indicating the country was not found. #### Error Response Example ```json { "error": "400" } ``` ``` -------------------------------- ### Get All Deaths Worldwide Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of COVID-19 deaths across all countries and a list of all tracked countries. ```APIDOC ## GET /deaths ### Description Returns the total number of COVID-19 deaths across all countries along with a list of all tracked countries. ### Method GET ### Endpoint /deaths ### Response #### Success Response (200) - **countries** (array of strings) - A list of country names. - **totalQuantity** (integer) - The total number of deaths worldwide. #### Response Example ```json { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 3456789 } ``` ``` -------------------------------- ### Get Recoveries by Country Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of recovered COVID-19 patients for a specific country. ```APIDOC ## GET /recovered/{country} ### Description Returns the total number of recovered patients for a specific country. ### Method GET ### Endpoint /recovered/{country} ### Parameters #### Path Parameters - **country** (string) - Required - The name of the country to retrieve data for. ### Response #### Success Response (200) - **country** (string) - The name of the country. - **totalQuantity** (integer) - The total number of recovered patients for the specified country. #### Response Example ```json { "country": "India", "totalQuantity": 9876543 } ``` #### Error Response (400) - **error** (string) - "400" indicating the country was not found. #### Error Response Example ```json { "error": "400" } ``` ``` -------------------------------- ### Get COVID-19 Statistics by Date and Country (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves specific COVID-19 statistics (cases, recovered, or deaths) for a given country on a particular date. This endpoint supports querying historical data and handles invalid parameters gracefully. ```bash curl -X GET http://localhost:4555/date/casos/Brazil/03-15-21 # Response { "country": "Brazil", "data": "2021-03-15T00:00:00", "count": 11693838 } # Using 'recuperados' (recovered) curl -X GET http://localhost:4555/date/recuperados/India/05-20-21 # Response { "country": "India", "data": "2021-05-20T00:00:00", "count": 8765432 } # Using 'mortes' (deaths) curl -X GET http://localhost:4555/date/mortes/US/01-10-21 # Response { "country": "US", "data": "2021-01-10T00:00:00", "count": 234567 } # Error Response (invalid parameters) { "error": "400" } ``` -------------------------------- ### Get All COVID-19 Recoveries Worldwide (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of recovered COVID-19 patients across all countries, along with a list of all tracked countries. This endpoint provides a global overview of recovery statistics. ```bash curl -X GET http://localhost:4555/recovered # Response { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 98765432 } ``` -------------------------------- ### Get COVID-19 Deaths by Country (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of COVID-19 deaths for a specific country. This endpoint allows for country-specific mortality data retrieval and includes error handling for invalid country inputs. ```bash curl -X GET http://localhost:4555/deaths/US # Response { "country": "US", "totalQuantity": 567890 } # Error Response (country not found) { "error": "400" } ``` -------------------------------- ### Get All Recoveries Worldwide Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of recovered COVID-19 patients across all countries and a list of all tracked countries. ```APIDOC ## GET /recovered ### Description Returns the total number of recovered patients across all countries along with a list of all tracked countries. ### Method GET ### Endpoint /recovered ### Response #### Success Response (200) - **countries** (array of strings) - A list of country names. - **totalQuantity** (integer) - The total number of recovered patients worldwide. #### Response Example ```json { "countries": ["US", "Brazil", "India", "Russia", "United Kingdom", ...], "totalQuantity": 98765432 } ``` ``` -------------------------------- ### Get COVID-19 Cases by Country (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of confirmed COVID-19 cases for a specific country. This endpoint allows users to query data for individual nations and handles cases where the country might not be found. ```bash curl -X GET http://localhost:4555/cases/Brazil # Response { "country": "Brazil", "totalQuantity": 12345678 } # Error Response (country not found) { "error": "400" } ``` -------------------------------- ### Get COVID-19 Recoveries by Country (API) Source: https://context7.com/sobeki/sistemacovid/llms.txt Retrieves the total number of recovered COVID-19 patients for a specific country. This endpoint is useful for tracking recovery rates in individual nations and includes error handling for unknown countries. ```bash curl -X GET http://localhost:4555/recovered/India # Response { "country": "India", "totalQuantity": 9876543 } # Error Response (country not found) { "error": "400" } ``` -------------------------------- ### Background Scheduler for Data Synchronization (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt Implements a background scheduler using 'apscheduler' to automatically synchronize COVID-19 data every 6 hours. It continuously runs in the background, fetching the latest data from the Johns Hopkins repository and updating the database. The scheduler can be stopped via keyboard interrupt or system exit. Requires 'apscheduler' and 'update_data' modules. ```python from apscheduler.schedulers.background import BackgroundScheduler from update_data import getDataFiles import time # Assuming time is imported for the sleep function # Initialize and start the scheduler scheduler = BackgroundScheduler() scheduler.add_job(getDataFiles, 'interval', hours=6) scheduler.start() # The scheduler runs in the background and automatically: # - Fetches latest data from Johns Hopkins repository # - Updates the database every 6 hours # - Keeps running until keyboard interrupt or system exit try: while True: time.sleep(2) except (KeyboardInterrupt, SystemExit): scheduler.shutdown() ``` -------------------------------- ### Automated Data Update System (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt This system automates the fetching and processing of COVID-19 data from the Johns Hopkins CSSE GitHub repository. It downloads confirmed cases, deaths, and recovered datasets, normalizes them by country, and updates the database. The process can be manually triggered or runs automatically every 6 hours. It relies on the 'update_data' module and 'pandas' for data manipulation. ```python from update_data import getDataFiles import pandas as pd # Manually trigger data update (also runs automatically every 6 hours) getDataFiles() # The function performs the following: # 1. Fetches file list from GitHub API # 2. Downloads time_series_covid19_confirmed_global.csv # 3. Downloads time_series_covid19_deaths_global.csv # 4. Downloads time_series_covid19_recovered_global.csv # 5. Normalizes data by grouping by country # 6. Inserts/updates database with new statistics # Example of what happens internally: # - Downloads CSV files to ./data/ directory # - Groups data by 'Country/Region' # - Sums values for countries with multiple provinces # - Converts date columns from "m/d/yy" format # - Inserts each date's statistics into database ``` -------------------------------- ### Retrieve COVID-19 Statistics (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt Provides functions to fetch worldwide and country-specific COVID-19 statistics (cases, recoveries, deaths). Includes error handling for cases where data might not be found, returning False in such scenarios. Requires the 'app.controller' module and 'datetime' for date handling. ```python from app.controller import ( getQueryTotalWorld, getQueryQuantidadeTotalByPais, getQueryByDataAndPaisRoute ) from datetime import datetime # Get worldwide cases total world_cases = getQueryTotalWorld('casos') # Returns: {'countries': [...], 'totalQuantity': 150234567} # Get country-specific recoveries brazil_recovered = getQueryQuantidadeTotalByPais('Brazil', 'recuperados') # Returns: {'country': 'Brazil', 'totalQuantity': 10123456} # Returns: False if country not found # Get historical data by date us_deaths = getQueryByDataAndPaisRoute('01-10-21', 'US', 'mortes') # Returns: {'country': 'US', 'data': datetime(2021,1,10), 'count': 234567} # Returns: False if no data found ``` -------------------------------- ### Insert COVID-19 Statistics Data (Python) Source: https://context7.com/sobeki/sistemacovid/llms.txt Provides a Python function `insert_query` to insert or update COVID-19 statistics (cases, recoveries, deaths) into the database. It automatically manages relationships and handles cases where the country or date entry might not exist, creating or updating as necessary. ```python from app.controller import insert_query from datetime import datetime # Insert cases data insert_query( data=datetime.strptime("03/15/21", "%m/%d/%y"), quantidade=11693838, nome_pais="Brazil", _type="casos" ) # Insert recoveries data insert_query( data=datetime.strptime("05/20/21", "%m/%d/%y"), quantidade=8765432, nome_pais="India", _type="recuperados" ) # Insert deaths data insert_query( data=datetime.strptime("01/10/21", "%m/%d/%y"), quantidade=234567, nome_pais="US", _type="mortes" ) # If country doesn't exist, it will be created automatically # If data for that date already exists, it will be updated ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.