from sqlalchemy import create_engine
import urllib.parse


h6_pg_us = {
    'user': 'adv_yswg002',
    # 'password': urllib.parse.quote('T#4$4%qPbR7mJx'),
    'password': 'T#4$4%qPbR7mJx',
    'host': '192.168.10.224',
    'port': 5433,
    'database': 'selection',
    # 'encoding': 'utf-8',
}

h14_pg_us = {
    "user": "postgres",
    # "password": urllib.parse.quote("G8m!Q2p9D#f%5x"),
    "password": "G8m!Q2p9D#f%5x",
    "host": "61.145.136.61",
    "port": 54328,
    "database": "selection",
}


def get_pg_country_engine(site_name="us"):
    if site_name == 'us' or site_name == 'mx':
        h6_pg_us["database"] = f"selection"
        db_ = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.format(*h6_pg_us.values())
    # elif site_name == "keepa":
    #     db_ = 'mysql+pymysql://{}:{}@{}:{}/{}?charset={}'.format(*h6_pg_us.values())
    else:
        h6_pg_us["database"] = f"selection_{site_name}"
        db_ = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.format(*h6_pg_us.values())
    engine = create_engine(db_, encoding='utf-8')  # , pool_recycle=3600
    return engine


def get_pg_con(site_name="us"):
    if site_name == 'us' or site_name == 'mx':
        h6_pg_us["database"] = f"selection"
        db_ = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.format(*h6_pg_us.values())
    # elif site_name == "keepa":
    #     db_ = 'mysql+pymysql://{}:{}@{}:{}/{}?charset={}'.format(*keepa_mysql.values())
    else:
        h6_pg_us["database"] = f"selection_{site_name}"
        db_ = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.format(*h6_pg_us.values())
    engine = create_engine(db_,  encoding='utf-8')
    conn = engine.connect()
    return conn


