def test_connection_is_closed_and_committed(loader, cursor, csv_path, table_schema_path, postgres_config_path): load('postgres', 'my_table', csv_path, table_schema_path, postgres_config_path) assert loader.connect.call_count == 1 assert loader._conn.commit.call_count == 1 assert loader._conn.close.call_count == 1
def test_run(loader, cursor, csv_path, table_schema_path, postgres_config_path): load('postgres', 'my_schema.my_table', csv_path, table_schema_path, postgres_config_path) assert clean_execute_call_list(cursor.execute.call_args_list) == [ "SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'my_schema' AND table_name = 'my_table' );", 'DROP TABLE IF EXISTS my_schema.my_table', 'CREATE SCHEMA IF NOT EXISTS "my_schema"; CREATE TABLE "my_schema"."my_table" (player VARCHAR(255), game_date_key INTEGER, game_at TIMESTAMP, turn INTEGER, branch VARCHAR(255), branch_level INTEGER, note VARCHAR(255), ornamentation VARCHAR(255), god VARCHAR(255));', "INSERT INTO \"my_schema\".\"my_table\" (player, game_date_key, game_at, turn, branch, branch_level, note, ornamentation, god) " "VALUES ('Chronos', 20181107, '2018-11-07 23:07:10', 1801, 'D', 2, 'Found a blossoming altar of Fedhas.', 'a blossoming', 'Fedhas')", "INSERT INTO \"my_schema\".\"my_table\" (player, game_date_key, game_at, turn, branch, branch_level, note, ornamentation, god) " "VALUES ('COBRA', 20180915, '2018-09-15 01:09:38', 790, 'D', 2, 'Found a white marble altar of Elyvilon.', 'a white marble', 'Elyvilon')", "INSERT INTO \"my_schema\".\"my_table\" (player, game_date_key, game_at, turn, branch, branch_level, note, ornamentation, god) " "VALUES ('CanOfBees', 20181017, '2018-10-17 13:16:48', 1449, 'D', 2, 'Found an iron altar of Okawaru.', 'an iron', 'Okawaru')", ]
def plot(plot_config: dict): plotter = line_plotter.LinePlotter() data = load_csv.load(filename=plot_config['file'], index=plot_config['index']) data = tuple(zip(*data)) for i, y in enumerate(data[1:]): plotter.add_line(ys=y, xs=data[0], color=kColors[i % len(kColors)]) # TODO add the states somewhere plotter.draw(title=plot_config['title'], share_coordinate=(plot_config['share_coordinate'] and plot_config['states'] is not None))
def test_cursors_are_closed(loader, cursor, csv_path, table_schema_path, postgres_config_path): load('postgres', 'my_table', csv_path, table_schema_path, postgres_config_path) assert cursor.__enter__.call_count == cursor.__exit__.call_count
server_file_date1 = soup.select(selector_date1)[0].text # string '2' server_file_date2 = soup.select(selector_date2)[0].text server_file_date = server_file_date1 + server_file_date2 print(local_file_date, server_file_date) if local_file_date != server_file_date: for file in files: os.remove('files/' + file) print('in IF') url_base = 'https://rossvyaz.ru/data/' files_on_server = [ 'ABC-3xx.csv', 'ABC-4xx.csv', 'ABC-8xx.csv', 'DEF-9xx.csv' ] for file in files_on_server: r = requests.get(url_base + file) path = 'files/' + file with open(path, 'wb') as f: f.write(r.content) new_name = file[:-4] + '-' + server_file_date + '.csv' print(new_name) os.rename('files/' + file, 'files/' + new_name) print(r.status_code) print(r.headers['content-type']) print(r.encoding) downloaded_files = os.listdir('files') load(downloaded_files)