From df33eaf258095b1ab269b56ec467065ee7020560 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 4 Sep 2022 10:12:57 -0700 Subject: [PATCH] update import/export scripts --- export.py | 8 +++++--- import.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/export.py b/export.py index 8d7463a..1ddb920 100755 --- a/export.py +++ b/export.py @@ -12,7 +12,7 @@ if not wallet.connected: print('Wallet not connected') exit() -all_posts = Post.select() +all_posts = Post.select().order_by(Post.timestamp.desc()) all_mods = Moderator.select() all_profiles = Profile.select() all_bans = Ban.select() @@ -27,7 +27,7 @@ all_data = { for post in all_posts: - all_data['posts'].append({ + post_data = { 'id': post.id, 'title': post.title, 'text': post.text, @@ -43,7 +43,9 @@ for post in all_posts: 'to_discord': post.to_discord, 'approved': post.approved, 'txes': wallet.transfers(post.account_index) - }) + } + all_data['posts'].append(post_data) + print(post_data['txes']) for mod in all_mods: all_data['moderators'].append(mod.username) diff --git a/import.py b/import.py index 8d6242d..51c8d99 100755 --- a/import.py +++ b/import.py @@ -51,11 +51,12 @@ for post in all_data['posts']: p = Post.get(post['id']) for tx in post['txes']['in']: if not TipReceived.select().where(TipReceived.txid == tx['txid']).first(): + amount = sum(tx['amounts']) TipReceived.create( post=p, timestamp=datetime.utcfromtimestamp(tx['timestamp']), txid=tx['txid'], - amount=sum(tx['amounts']), + amount=amount, fee=tx['fee'] ) print(f'Saving received tip txid {tx["txid"]}') @@ -65,7 +66,8 @@ for post in all_data['posts']: for tx in post['txes']['out']: if not TipSent.select().where(TipSent.txid == tx['txid']).first(): TipSent.create( - user=p.user, + from_user=p.user, + to_user=p.user, txid=tx['txid'], timestamp=datetime.utcfromtimestamp(tx['timestamp']), amount=tx['amount'],