<jupyter_start><jupyter_text>Background Current implementation of database does not have ICAN names and this is needed to work with topoJSONGoal: use new api from [here](https://github.com/mathdroid/covid-19-api)  Install libraries<jupyter_code>pip install flask_sqlalchemy<jupyter_output>Collecting flask_sqlalchemy
  Downloading https://files.pythonhosted.org/packages/1e/65/226d95466c75e34e291a76890ed0e27af2e46ab913002847856f11d4d59d/Flask_SQLAlchemy-2.4.1-py2.py3-none-any.whl
Requirement already satisfied: SQLAlchemy>=0.8.0 in /usr/local/lib/python3.6/dist-packages (from flask_sqlalchemy) (1.3.16)
Requirement already satisfied: Flask>=0.10 in /usr/local/lib/python3.6/dist-packages (from flask_sqlalchemy) (1.1.2)
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10->flask_sqlalchemy) (2.11.2)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10->flask_sqlalchemy) (7.1.1)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10->flask_sqlalchemy) (1.1.0)
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10->flask_sqlalchemy) (1.0.1)
Requirement already satisfied: Ma[...]<jupyter_text>Imports<jupyter_code># db model
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# create & update
from datetime import datetime, timedelta
import requests

# lstm
import pandas as pd
import numpy as np
import random as rn

# model
import tensorflow as tf
from keras.models import Sequential
from keras.layers import LSTM
from keras.layers import Dense
from keras.losses import MeanSquaredLogarithmicError
from sklearn.model_selection import train_test_split

# predict
from keras.models import load_model
import collections<jupyter_output>Using TensorFlow backend.<jupyter_text>Create Model<jupyter_code># load flask
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///site.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

# load db
db = SQLAlchemy(app)

# db models
class Stat(db.Model):
    id = db.Column(db.String(120), primary_key=True)
    country = db.Column(db.String(100), unique=False, nullable=False)
    ican3 = db.Column(db.String(3), nullable=False)
    date = db.Column(db.Date, nullable=False)
    confirmed = db.Column(db.Integer)
    deaths = db.Column(db.Integer)
    recovered = db.Column(db.Integer)
    confirmed_pred = db.Column(db.Integer)
    deaths_pred = db.Column(db.Integer)
    recovered_pred = db.Column(db.Integer)

    def __repr__(self):
        return f"Stat('{self.country}', '{self.date}', '{self.confirmed}', '{self.deaths}', '{self.recovered}',  '{self.confirmed_pred}', '{self.deaths_pred}', '{self.recovered_pred}')"<jupyter_output><empty_output><jupyter_text>Create Database Model  Pseudocode 1. get countries2. for each country, get stats for every day3. save into database<jupyter_code># variables
base = 'https://covid19.mathdro.id'
country_url = '/api/countries'
# get countries
country_res = requests.get(f'{base}{country_url}')
countries = country_res.json()['countries'] ; countries[:5]
country_map = {}
for country in countries:
    # note iso can be None
    iso3, name = country.get('iso3', None), country['name']
    country_map[name] = iso3
    # print(iso3, name)
    # print(country_map)
    # break
len(country_map)<jupyter_output><empty_output><jupyter_text>For each country, find their ICAN CODE<jupyter_code>match_country = [('Afghanistan'), ('Albania'), ('Algeria'), ('Andorra'), ('Angola'), ('Antigua and Barbuda'), ('Argentina'), ('Armenia'), ('Australia'), ('Austria'), ('Azerbaijan'), ('Bahamas'), ('Bahrain'), ('Bangladesh'), ('Barbados'), ('Belarus'), ('Belgium'), ('Benin'), ('Bhutan'), ('Bolivia'), ('Bosnia and Herzegovina'), ('Brazil'), ('Brunei'), ('Bulgaria'), ('Burkina Faso'), ('Cabo Verde'), ('Cambodia'), ('Cameroon'), ('Canada'), ('Central African Republic'), ('Chad'), ('Chile'), ('China'), ('Colombia'), ('Congo (Brazzaville)'), ('Congo (Kinshasa)'), ('Costa Rica'), ("Cote d'Ivoire"), ('Croatia'), ('Diamond Princess'), ('Cuba'), ('Cyprus'), ('Czechia'), ('Denmark'), ('Djibouti'), ('Dominican Republic'), ('Ecuador'), ('Egypt'), ('El Salvador'), ('Equatorial Guinea'), ('Eritrea'), ('Estonia'), ('Eswatini'), ('Ethiopia'), ('Fiji'), ('Finland'), ('France'), ('Gabon'), ('Gambia'), ('Georgia'), ('Germany'), ('Ghana'), ('Greece'), ('Guatemala'), ('Guinea'), ('Guyana'), ('Haiti'), ('Holy See'), ('Honduras'), ('Hungary'), ('Iceland'), ('India'), ('Indonesia'), ('Iran'), ('Iraq'), ('Ireland'), ('Israel'), ('Italy'), ('Jamaica'), ('Japan'), ('Jordan'), ('Kazakhstan'), ('Kenya'), ('Korea, South'), ('Kuwait'), ('Kyrgyzstan'), ('Latvia'), ('Lebanon'), ('Liberia'), ('Liechtenstein'), ('Lithuania'), ('Luxembourg'), ('Madagascar'), ('Malaysia'), ('Maldives'), ('Malta'), ('Mauritania'), ('Mauritius'), ('Mexico'), ('Moldova'), ('Monaco'), ('Mongolia'), ('Montenegro'), ('Morocco'), ('Namibia'), ('Nepal'), ('Netherlands'), ('New Zealand'), ('Nicaragua'), ('Niger'), ('Nigeria'), ('North Macedonia'), ('Norway'), ('Oman'), ('Pakistan'), ('Panama'), ('Papua New Guinea'), ('Paraguay'), ('Peru'), ('Philippines'), ('Poland'), ('Portugal'), ('Qatar'), ('Romania'), ('Russia'), ('Rwanda'), ('Saint Lucia'), ('Saint Vincent and the Grenadines'), ('San Marino'), ('Saudi Arabia'), ('Senegal'), ('Serbia'), ('Seychelles'), ('Singapore'), ('Slovakia'), ('Slovenia'), ('Somalia'), ('South Africa'), ('Spain'), ('Sri Lanka'), ('Sudan'), ('Suriname'), ('Sweden'), ('Switzerland'), ('Taiwan*'), ('Tanzania'), ('Thailand'), ('Togo'), ('Trinidad and Tobago'), ('Tunisia'), ('Turkey'), ('Uganda'), ('Ukraine'), ('United Arab Emirates'), ('United Kingdom'), ('Uruguay'), ('US'), ('Uzbekistan'), ('Venezuela'), ('Vietnam'), ('Zambia'), ('Zimbabwe'), ('Dominica'), ('Grenada'), ('Mozambique'), ('Syria'), ('Timor-Leste'), ('Belize'), ('Laos'), ('Libya'), ('West Bank and Gaza'), ('Guinea-Bissau'), ('Mali'), ('Saint Kitts and Nevis'), ('Kosovo'), ('Burma'), ('MS Zaandam'), ('Botswana'), ('Burundi'), ('Sierra Leone'), ('Malawi'), ('South Sudan'), ('Western Sahara'), ('Sao Tome and Principe'), ('Yemen')]
for country in match_country:
    if country not in country_map:
        print(country)
'Korea, South' in country_map
country_map['Korea, South']
country_map<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21629213483146068, 'fraction_numerical': 0.020911360799001247, 'mean_word_length': 6.971393034825871, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '311910', 'license': 'MIT', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2203, 'n_words': 515, 'path': 'eda/Covid_Api_Pull.ipynb', 'repo_name': 'Dangandy/covid', 'size': '6408'}