dummy data for local dev

master
lza_menace 2 years ago
parent be8aef16cc
commit c31535d059

@ -1,4 +1,8 @@
import click import click
from os import path, makedirs
from urllib.request import urlopen
from nerochan.models import User, Artwork
def cli(app): def cli(app):
@ -9,4 +13,55 @@ def cli(app):
model = peewee.Model.__subclasses__() model = peewee.Model.__subclasses__()
db.create_tables(model) 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 return app

@ -70,9 +70,9 @@ class Profile(pw.Model):
database = db 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() id = pw.AutoField()
creator = pw.ForeignKeyField(User) creator = pw.ForeignKeyField(User)
@ -82,7 +82,7 @@ class Content(pw.Model):
approved = pw.BooleanField(default=False) approved = pw.BooleanField(default=False)
hidden = pw.BooleanField(default=False) hidden = pw.BooleanField(default=False)
title = pw.CharField() title = pw.CharField()
description = pw.TextField() description = pw.TextField(null=True)
class Meta: class Meta:
database = db database = db
@ -97,7 +97,7 @@ class Transaction(pw.Model):
tx_id = pw.CharField(unique=True) tx_id = pw.CharField(unique=True)
atomic_xmr = pw.BigIntegerField() atomic_xmr = pw.BigIntegerField()
to_address = pw.CharField() to_address = pw.CharField()
content = pw.ForeignKeyField(Content) content = pw.ForeignKeyField(Artwork)
class Meta: class Meta:
database = db database = db

@ -1,14 +1,14 @@
from flask import Blueprint, render_template, flash, redirect, url_for from flask import Blueprint, render_template, flash, redirect, url_for
from flask_login import login_required 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 = Blueprint('artwork', 'artwork', url_prefix='/artwork')
@bp.route('/<int:artwork_id>') @bp.route('/<int:artwork_id>')
def show(artwork_id): def show(artwork_id):
artwork = Content.get_or_none(artwork_id) artwork = Artwork.get_or_none(artwork_id)
if not artwork: if not artwork:
flash('That artwork does not exist.', 'warning') flash('That artwork does not exist.', 'warning')
return redirect(url_for('main.index')) return redirect(url_for('main.index'))

Loading…
Cancel
Save