From 70ccd5751938c032b68e7a304c2dfe3faba883c7 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 5 Sep 2022 20:08:40 -0700 Subject: [PATCH] update wallet and generate dummy data --- requirements.txt | 1 + run_wallets.sh | 2 +- suchwow/_models.py | 7 +++++-- suchwow/cli.py | 34 +++++++++++++++++++++++++++++++- suchwow/templates/post/read.html | 2 +- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 93e02c0..0b0cea2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ qrcode Pillow arrow python-dotenv +lorem \ No newline at end of file diff --git a/run_wallets.sh b/run_wallets.sh index 6249126..7f05f45 100755 --- a/run_wallets.sh +++ b/run_wallets.sh @@ -21,7 +21,7 @@ fi # run rpc process docker run --restart=always -d --name suchwow-wallet-rpc \ -v $WALLET_PATH:/root \ - -p 8888:8888 \ + -p $WALLET_PORT:8888 \ lalanza808/wownero:latest \ wownero-wallet-rpc \ --daemon-address $DAEMON_URI \ diff --git a/suchwow/_models.py b/suchwow/_models.py index 91aa34b..e737764 100644 --- a/suchwow/_models.py +++ b/suchwow/_models.py @@ -57,13 +57,16 @@ class Post(Model): account_index = IntegerField() address_index = IntegerField(unique=True) address = CharField(unique=True) - timestamp = DateTimeField(default=datetime.now) + timestamp = DateTimeField(default=datetime.utcnow) approved = BooleanField(default=False) approved_by = ForeignKeyField(User, null=True) def get_random(self): all_posts = Post.select().where(Post.approved == True) - return choice([i.id for i in all_posts]) + if all_posts: + return choice([i.id for i in all_posts]) + else: + return None def get_previous(self): prev = Post.select().where(Post.id == self.id - 1).first() diff --git a/suchwow/cli.py b/suchwow/cli.py index 7f6ad31..92c82a0 100644 --- a/suchwow/cli.py +++ b/suchwow/cli.py @@ -1,5 +1,7 @@ -from os import makedirs +from os import makedirs, getenv +from random import choice +import lorem from flask import Blueprint from suchwow._models import db, User, Post, AuditEvent, TipSent, TipReceived, Vote @@ -19,6 +21,36 @@ def init(): # init db db.create_tables([User, Post, AuditEvent, TipSent, TipReceived, Vote]) +@bp.cli.command('generate_data') +def generate_data(): + if getenv('FLASK_DEBUG', 0) == '1': + users = ['lza_menace', 'wowario', 'jwinterm', 'dsc', 'asymptotically'] + for user in users: + moderator = False + if not User.select().where(User.username == user): + if user == 'lza_menace': + moderator = True + User.create( + username=user, + moderator=moderator + ) + print(f'Created user {user}') + + for i in range(1, 5): + wallet = wownero.Wallet() + address_idx, address = wallet.new_address(config.WALLET_ACCOUNT) + wallet.store() + Post.create( + title=lorem.sentence(), + text=lorem.sentence(), + user=choice(list(User.select())), + image_name='test.jpg', + account_index=config.WALLET_ACCOUNT, + address_index=address_idx, + address=address + ) + + @bp.cli.command('rescan') def rescan(): diff --git a/suchwow/templates/post/read.html b/suchwow/templates/post/read.html index b0a7ba9..474d0b3 100644 --- a/suchwow/templates/post/read.html +++ b/suchwow/templates/post/read.html @@ -21,7 +21,7 @@
  • - + Random