diff --git a/import.py b/import.py index 51c8d99..9cc29c0 100755 --- a/import.py +++ b/import.py @@ -50,8 +50,13 @@ for post in all_data['posts']: if 'in' in post['txes']: 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']) + amount = sum(tx['amounts']) + received = TipReceived.select().where( + TipReceived.txid == tx['txid'], + TipReceived.amount == amount, + TipReceived.post == p + ).first() + if not received: TipReceived.create( post=p, timestamp=datetime.utcfromtimestamp(tx['timestamp']), diff --git a/suchwow/_models.py b/suchwow/_models.py index 8620705..f43b019 100644 --- a/suchwow/_models.py +++ b/suchwow/_models.py @@ -156,7 +156,8 @@ class Post(Model): 'approved': self.approved, 'approved_by': self.approved_by, 'received_wow': self.get_wow_received(), - 'hours_elapsed': self.hours_elapsed() + 'hours_elapsed': self.hours_elapsed(), + 'tips_received': [tip for tip in TipReceived.select().where(TipReceived.post == self)] } class Meta: @@ -195,7 +196,7 @@ class AuditEvent(Model): class TipReceived(Model): id = AutoField() post = ForeignKeyField(Post) - txid = CharField(unique=True) + txid = CharField() timestamp = DateTimeField() amount = IntegerField() fee = IntegerField() @@ -208,7 +209,7 @@ class TipSent(Model): id = AutoField() from_user = ForeignKeyField(User) to_user = ForeignKeyField(User) - txid = CharField(unique=True) + txid = CharField() timestamp = DateTimeField() amount = IntegerField() fee = IntegerField() diff --git a/sync_remote.sh b/sync_remote.sh new file mode 100644 index 0000000..49763fc --- /dev/null +++ b/sync_remote.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +rsync -avzP australia:/opt/suchwow/data/uploads/ data/uploads/ +rsync -avzP australia:/opt/suchwow/data/sqlite.db data/sqlite.db +rsync -avzP australia:/opt/suchwow/data/migrate_data.pkl data/migrate_data.pkl +.venv/bin/python3 import.py +