#!/usr/bin/env python3 import sqlite3 import json import sys # this script integrates the invitations database in the main database working with the newer scheme def convert_invs(c): l = {} c.execute('''SELECT * FROM invitations;''') for row in c: if row[1] not in l: l[row[1]] = [(row[0], row[2])] else: l[row[1]].append((row[0], row[2])) for room in l.keys(): jsondata = json.dumps(list(l[room])) c.execute("""INSERT INTO main.room_plugin_data VALUES (?, 'invite', 'invitetokens', ?);""", (room, jsondata)) def load_dbs(new_db, inv_db): conn = sqlite3.connect(new_db) c = conn.cursor() conn.execute("""ATTACH DATABASE (?) AS inv;""", (inv_db,)); return conn def main(): if (len(sys.argv) != 3): print("Usage: convert_invitations new_db inv_db") return conn = load_dbs(sys.argv[1], sys.argv[2]) c = conn.cursor() convert_invs(c) conn.commit() if __name__ == "__main__": main()