In [1]:
from matplotlib import pyplot as plt
from eralchemy import render_er
from IPython.display import display
from PIL import Image
from datetime import datetime, date, timedelta
import os
import matplotlib as mpl
import numpy as np
import pandas as pd
import psycopg2
import pytz
import sys
import sqlalchemy as sqla
In [2]:
dir_root = os.path.dirname(os.getcwd())
dir_app = os.path.join(
dir_root, 'AlertaDengue'
)
sys.path.insert(0, dir_app)
from AlertaDengue import settings
from dados import dbdata
In [3]:
# connection
db_dsn = 'postgresql://{}:{}@{}/{}'.format(
settings.PSQL_USER,
settings.PSQL_PASSWORD,
settings.PSQL_HOST,
settings.PSQL_DB)
engine = sqla.create_engine(db_dsn)
# connection info_dengue
db_dsn2 = 'postgresql://{}:{}@{}/{}'.format(
settings.PSQL_USER,
settings.PSQL_PASSWORD,
settings.PSQL_HOST,
'infodengue')
engine_info_dengue = sqla.create_engine(db_dsn2)
In [4]:
# scheme
pd.read_sql('SELECT nspname FROM pg_catalog.pg_namespace;', engine)
# Dengue_global
# Municipio
Out[4]:
In [5]:
# Schema: Dengue_global
sql = '''
SELECT table_name
FROM information_schema.tables
WHERE table_schema='Dengue_global'
ORDER BY table_schema,table_name;
'''
display(pd.read_sql(sql, engine))
render_er(db_dsn, '/tmp/img.png', schema='Dengue_global')
Image.open('/tmp/img.png')
Out[5]:
In [6]:
sql = 'SELECT * from "Dengue_global"."Municipio"'
pd.read_sql(sql, engine).head()
Out[6]:
In [7]:
# Schema: Municipio
sql = '''
SELECT table_name
FROM information_schema.tables
WHERE table_schema='Municipio'
ORDER BY table_schema,table_name;
'''
display(pd.read_sql(sql, engine))
render_er(db_dsn, '/tmp/img.png', schema='Municipio')
Image.open('/tmp/img.png')
Out[7]:
In [8]:
# Schema: public
sql = '''
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
ORDER BY table_schema,table_name;
'''
display(pd.read_sql(sql, engine_info_dengue))
render_er(db_dsn2, '/tmp/img.png', schema='public')
Image.open('/tmp/img.png')
Out[8]: