diff --git a/nerochan/cli.py b/nerochan/cli.py index f2b28ea..9883f18 100644 --- a/nerochan/cli.py +++ b/nerochan/cli.py @@ -1,4 +1,8 @@ import click +from os import path, makedirs +from urllib.request import urlopen + +from nerochan.models import User, Artwork def cli(app): @@ -9,4 +13,55 @@ def cli(app): model = peewee.Model.__subclasses__() db.create_tables(model) + @app.cli.command('generate_data') + def generate_data(): + data = { + 'nerodude': { + 'wallet': '797P5cwQA2LHxPqfnsMgPwbfTGk6JAcibSPo6jV75uGx4Am7sZRbE1R5HJ7urWCDWNV51tPWtzyY1JMiUTXrXdu93YfjrdH', + 'art': [ + 'https://www.monerochan.art/commissions/monerochan-beach.jpg', + 'https://www.monerochan.art/commissions/mememe.gif', + 'https://www.monerochan.art/commissions/iwantyou.jpg' + ] + }, + 'weedburpz': { + 'wallet': '77toDDnVmSrWMZ5tS17UWXcxQVkD6LtNSArVwzsWdE176oDbYtPTiAqExjDZWGE5KwKPY7Kd1BcWYfCnJuL2RfcqA1gzoEj', + 'art': [ + 'https://www.monerochan.art/commissions/hammock.png', + 'https://www.monerochan.art/commissions/assaultrifle.png' + ] + } + } + for user in data: + _user = User.select().where(User.handle == user).first() + if not _user: + u = User( + handle=user, + wallet_address=data[user]['wallet'] + ) + u.save() + _user = u + click.echo(f'[+] Created user {user}') + + for art in data[user]['art']: + makedirs('./data/uploads', exist_ok=True) + bn = path.basename(art) + fp = f'./data/uploads/{bn}' + if not path.exists(fp): + with urlopen(art) as img: + content = img.read() + with open(fp, 'wb') as download: + download.write(content) + click.echo(f'[+] Downloaded {art}') + if not Artwork.select().where(Artwork.path == bn).first(): + artwork = Artwork( + creator=_user, + path=bn, + approved=True, + title=f'i made {bn}', + description='' + ) + artwork.save() + click.echo(f'[+] Created artwork {artwork.id} for {bn}') + return app diff --git a/nerochan/models.py b/nerochan/models.py index f753a55..d19ead0 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -70,9 +70,9 @@ class Profile(pw.Model): database = db -class Content(pw.Model): +class Artwork(pw.Model): """ - Content model is any uploaded content from a creator. + Artwork model is any uploaded content from a creator. """ id = pw.AutoField() creator = pw.ForeignKeyField(User) @@ -82,7 +82,7 @@ class Content(pw.Model): approved = pw.BooleanField(default=False) hidden = pw.BooleanField(default=False) title = pw.CharField() - description = pw.TextField() + description = pw.TextField(null=True) class Meta: database = db @@ -97,7 +97,7 @@ class Transaction(pw.Model): tx_id = pw.CharField(unique=True) atomic_xmr = pw.BigIntegerField() to_address = pw.CharField() - content = pw.ForeignKeyField(Content) + content = pw.ForeignKeyField(Artwork) class Meta: database = db diff --git a/nerochan/routes/artwork.py b/nerochan/routes/artwork.py index 135fd3a..57dbca8 100644 --- a/nerochan/routes/artwork.py +++ b/nerochan/routes/artwork.py @@ -1,14 +1,14 @@ from flask import Blueprint, render_template, flash, redirect, url_for from flask_login import login_required -from nerochan.models import Content, User +from nerochan.models import Artwork, User bp = Blueprint('artwork', 'artwork', url_prefix='/artwork') @bp.route('/') def show(artwork_id): - artwork = Content.get_or_none(artwork_id) + artwork = Artwork.get_or_none(artwork_id) if not artwork: flash('That artwork does not exist.', 'warning') return redirect(url_for('main.index'))