diff --git a/backend/src/kibicara/migratefromticketfrei.py b/backend/src/kibicara/migratefromticketfrei.py index db8a81c..733687c 100644 --- a/backend/src/kibicara/migratefromticketfrei.py +++ b/backend/src/kibicara/migratefromticketfrei.py @@ -3,6 +3,7 @@ import argparse from time import time, sleep from os import urandom from tortoise import Tortoise +from tortoise.exceptions import DoesNotExist import asyncio from kibicara.model import Admin, Hood, IncludePattern, ExcludePattern @@ -18,8 +19,6 @@ class OldDataBase: self.cur = self.conn.cursor() def execute(self, *args, **kwargs): - if len(args) > 1: - print(args[0], args[1][0]) return self.cur.execute(*args, **kwargs) def commit(self): @@ -83,16 +82,13 @@ class Main: url = instance[1] client_id = instance[2] client_secret = instance[3] - print(url) - print(client_id) - print(client_secret) await MastodonInstance.create( name=url, client_id=client_id, client_secret=client_secret ) + print(f"Created Mastodon Instance: {url}") old_users = self.old_db.execute("SELECT * FROM user;").fetchall() for user in old_users: - print(user) user_id = user[0] user_passhash = user[1] user_enabled = user[2] @@ -103,31 +99,36 @@ class Main: email = self.old_db.execute( "SELECT email FROM email WHERE user_id=?", (user_id,) ).fetchone()[0] - print("email:", email) - admin = await Admin.create(email=email, passhash=user_passhash) + try: + await Admin.get(email=email) + continue # skip if the user already exists. + except DoesNotExist: + admin = await Admin.create(email=email, passhash=user_passhash) city = self.old_db.execute( "SELECT * FROM cities WHERE user_id=?", (user_id,) ).fetchone() city_name = city[2] city_markdown = city[3] - # print(city_name) - # print(city_markdown) hood = await Hood.create(name=city_name, landingpage=city_markdown) await hood.admins.add(admin) + print() + print( + "Migrated user %s with email %s for the city %s" + "with the following accounts:" % (user_id, email, city_name) + ) + patterns = self.old_db.execute( "SELECT patterns FROM triggerpatterns WHERE user_id=?", (user_id,) ).fetchone()[0] for pattern in patterns.splitlines(): - print("trigger:", pattern) await IncludePattern.create(hood=hood, pattern=pattern) badwords = self.old_db.execute( "SELECT words FROM badwords WHERE user_id=?", (user_id,) ).fetchone()[0] for badword in badwords.splitlines(): - print("bad word:", badword) await ExcludePattern.create(hood=hood, pattern=badword) mastodon_account = self.old_db.execute( @@ -147,9 +148,7 @@ class Main: access_token=access_token, enabled=mastodon_enabled, ) - # print(instance_url) - # print(access_token) - # print(mastodon_enabled) + print(f"Mastodon: {instance_url}, {access_token}") telegram_account = self.old_db.execute( "SELECT apikey, active FROM telegram_accounts WHERE user_id=?", @@ -158,8 +157,6 @@ class Main: if telegram_account[0] != "": telegram_apikey = telegram_account[0] telegram_enabled = telegram_account[1] - # print(telegram_apikey) - # print(telegram_enabled) telegram = await Telegram.create( hood=hood, api_token=telegram_apikey, @@ -173,6 +170,7 @@ class Main: for subscriber in telegram_subscribers: subscriber_id = subscriber[0] await TelegramSubscriber.create(bot=telegram, user_id=subscriber_id) + print(f"Telegram: {len(telegram_subscribers)} subscribers") mail_subscribers = self.old_db.execute( "SELECT email FROM mailinglist WHERE user_id=?", (user_id,) @@ -185,7 +183,7 @@ class Main: for subscriber in mail_subscribers: subscriber_email = subscriber[0] await EmailSubscriber.create(email=subscriber_email, hood=hood) - # print("subscriber:", subscriber_email) + print(f"E-Mail: {len(mail_subscribers)} subscribers") twitter = self.old_db.execute( "SELECT * FROM twitter_accounts WHERE user_id=?", (user_id,) @@ -206,4 +204,5 @@ class Main: verified=False, enabled=True, ) + print(f"Twitter: last ID: {seen_tweet}") await Tortoise.close_connections()