Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @contextmanager
- def conn_context(db_path):
- conn = sqlite3.connect(db_path)
- conn.row_factory = sqlite3.Row
- yield conn
- conn.close()
- class PostgresSaver:
- def __init__(self, pg_conn: _connection):
- self.connection = pg_conn
- self.cursor = pg_conn.cursor()
- def save_all_data(self, ...):
- ...
- class SQLiteExtractor:
- def __init__(self, connection):
- self.conn = connection
- self.cur = self.conn.cursor()
- def extract_movies(self, ...):
- ...
- def load_from_sqlite(connection: sqlite3.Connection, pg_con: _connection):
- postgres_saver = PostgresSaver(pg_con)
- sqlite_extractor = SQLiteExtractor(connection)
- ...
- if __name__ == '__main__':
- with (conn_context('db.sqlite') as sqlite_conn,
- psycopg2.connect(**dsl, cursor_factory=DictCursor) as pg_conn):
- load_from_sqlite(sqlite_conn, pg_conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement