Skip to content

Instantly share code, notes, and snippets.

@mozlima
Forked from mikf/merge_gdl_archives.py
Created February 27, 2025 01:56
Show Gist options
  • Save mozlima/eb007bab894c6c187d42d87a2518f92a to your computer and use it in GitHub Desktop.
Save mozlima/eb007bab894c6c187d42d87a2518f92a to your computer and use it in GitHub Desktop.
#!/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