Last active
February 27, 2025 01:56
-
-
Save mikf/7b9fd9112289d19b749d8868d684ba45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Name | |
merge_gdl_archives - merge multiple download archives into one | |
Usage | |
merge_gdl_archives.py merged.sqlite old1.sqlite old2.sqlite ... | |
""" | |
import sqlite3 | |
import sys | |
def open_database(path): | |
db = sqlite3.connect(path, timeout=60, check_same_thread=False) | |
db.isolation_level = None | |
return db | |
def main(): | |
with open_database(sys.argv[1]) as main_db: | |
main_cursor = main_db.cursor() | |
main_cursor.execute("CREATE TABLE IF NOT EXISTS archive " | |
"(entry PRIMARY KEY) WITHOUT ROWID") | |
for db_path in sys.argv[2:]: | |
with open_database(db_path) as db: | |
main_cursor.execute("BEGIN TRANSACTION") | |
for row in db.execute("SELECT entry FROM archive"): | |
main_cursor.execute( | |
"INSERT OR IGNORE INTO archive VALUES (?)", (row[0],)) | |
main_cursor.execute("COMMIT") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment