Ejemplo n.º 1
0
def main():
    parser = define_parser()
    args = parser.parse_args()
    parameter_check_with_condition(
        parser, ("key", args.key, is_not_none),
        ("start_date", args.start_date, is_not_none),
        ("end_date", args.end_date, is_not_none))

    dbtype, dbfilename = (DBType.sqlite3, args.dbfile) if args.dbfile is not None else \
        (DBType.memory, None)

    db_session_open(
        db_session_string=db_session_string_definition(dbtype,
                                                       file_path=dbfilename),
        db_definition_method_table={
            exchange_rate_item_table_name: get_exchange_rate_item_db
        })
    session, table_definition = EnvStore.get_env(db_session_tables)
    ExchangeRateItem = table_definition[exchange_rate_item_table_name]
    for one_date in date_iterator(args.start_date, args.end_date):
        for item_to_save in resp_dict_converter(
                request_exchange(key=args.key,
                                 search_date=one_date.strftime("%Y%m%d"))):
            session.add(ExchangeRateItem(**item_to_save, date=one_date))
    session.commit()
    if dbtype == DBType.memory:
        pprint(session.query(ExchangeRateItem).all())
Ejemplo n.º 2
0
def test_db_session_open():
    db_session_open(
        db_session_string=db_session_string_definition(DBType.memory),
        db_definition_method_table={
            exchange_rate_item_table_name: get_exchange_rate_item_db
        })
    session, table_definition = EnvStore.get_env(db_session_tables)
    ExchangeRateItem = table_definition[exchange_rate_item_table_name]
    session.add(
        ExchangeRateItem(date=date(2018, 1, 1),
                         bkrp=10.1,
                         cur_nm="1111",
                         cur_unit="ABCD",
                         deal_bas_r=10.2,
                         kftc_bkpr=10.3,
                         kftc_deal_bas_r=10.4,
                         result=1,
                         ten_dd_efee_r=10.5,
                         ttb=10.6,
                         tts=10.7,
                         yy_efee_r=10.8))
    session.commit()
    assert session.query(ExchangeRateItem).first().bkrp == 10.1
def test_db_session_string_definition_sqlite():
    assert "sqlite:///a.db" == db_session_string_definition(DBType.sqlite3, file_path="a.db")
def test_db_session_string_definition_memory():
    assert "sqlite://" == db_session_string_definition(DBType.memory)
def test_db_session_string_definition_psql():
    assert "postgres://*****:*****@127.0.0.1:5000/dbn" == db_session_string_definition(DBType.postgres, username="******", password="******", ipaddr="127.0.0.1", port=5000, dbname="dbn")
def test_db_session_string_definition_psql_error5():
    db_session_string_definition(DBType.postgres, username="******", password="******", ipaddr="127.0.0.1", port=5000)
def test_db_session_string_definition_psql_error3():
    db_session_string_definition(DBType.postgres, username="******", password="******")
def test_db_session_string_definition_psql_error2():
    db_session_string_definition(DBType.postgres, username="******")
def test_db_session_string_definition_psql_error1():
    db_session_string_definition(DBType.postgres)
def test_db_session_string_definition_sqlite_error():
    db_session_string_definition(DBType.sqlite3)