forked from lza_menace/suchwow
parent
d0ff90dd5c
commit
4d8ede1ea8
@ -1,43 +1,63 @@
|
|||||||
from flask import jsonify, Blueprint, url_for, request, abort
|
from flask import jsonify, Blueprint, url_for, request, abort
|
||||||
from suchwow.models import Post
|
from suchwow.models import Post
|
||||||
from suchwow import wownero
|
from suchwow import wownero
|
||||||
|
|
||||||
|
from suchwow.utils.helpers import rw_cache, get_top_posters, get_top_posts
|
||||||
bp = Blueprint("api", "api")
|
|
||||||
|
|
||||||
@bp.route("/api/list")
|
bp = Blueprint("api", "api")
|
||||||
def api_list():
|
|
||||||
limit = request.args.get('limit', 30)
|
|
||||||
offset = request.args.get('offset', 0)
|
@bp.route("/api/list")
|
||||||
|
def api_list():
|
||||||
# Hacky way to convert query str value to int
|
limit = request.args.get('limit', 30)
|
||||||
try:
|
offset = request.args.get('offset', 0)
|
||||||
limit = int(limit)
|
|
||||||
offset = int(offset)
|
# Hacky way to convert query str value to int
|
||||||
except:
|
try:
|
||||||
abort(500, "Bleep bleep")
|
limit = int(limit)
|
||||||
|
offset = int(offset)
|
||||||
if limit > 30:
|
except:
|
||||||
limit = 30
|
abort(500, "Bleep bleep")
|
||||||
|
|
||||||
all_posts = []
|
if limit > 30:
|
||||||
posts = Post.select().where(Post.approved==True).order_by(Post.timestamp.desc()).limit(limit).offset(offset)
|
limit = 30
|
||||||
for post in posts:
|
|
||||||
wallet = wownero.Wallet()
|
all_posts = []
|
||||||
if wallet.connected:
|
posts = Post.select().where(Post.approved == True).order_by(
|
||||||
address = wallet.get_address(account=post.account_index)
|
Post.timestamp.desc()).limit(limit).offset(offset)
|
||||||
else:
|
for post in posts:
|
||||||
address = ''
|
wallet = wownero.Wallet()
|
||||||
|
if wallet.connected:
|
||||||
payload = {
|
address = wallet.get_address(account=post.account_index)
|
||||||
'image': url_for('post.uploaded_file', filename=post.image_name, _external=True),
|
else:
|
||||||
'submitter': post.submitter,
|
address = ''
|
||||||
'address': address,
|
|
||||||
'title': post.title,
|
payload = {
|
||||||
'text': post.text,
|
'image': url_for('post.uploaded_file', filename=post.image_name, _external=True),
|
||||||
'href': url_for('post.read', id=post.id, _external=True),
|
'submitter': post.submitter,
|
||||||
'id': post.id,
|
'address': address,
|
||||||
'timestamp': post.timestamp
|
'title': post.title,
|
||||||
}
|
'text': post.text,
|
||||||
all_posts.append(payload)
|
'href': url_for('post.read', id=post.id, _external=True),
|
||||||
return jsonify(all_posts)
|
'id': post.id,
|
||||||
|
'timestamp': post.timestamp
|
||||||
|
}
|
||||||
|
all_posts.append(payload)
|
||||||
|
return jsonify(all_posts)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route("/api/posters")
|
||||||
|
def api_posters():
|
||||||
|
|
||||||
|
posters = get_top_posters()
|
||||||
|
all_posters = {}
|
||||||
|
for poster, data in posters.items():
|
||||||
|
payload = {
|
||||||
|
"submitter": poster,
|
||||||
|
"posts": data["posts"],
|
||||||
|
"amount": data["amount"],
|
||||||
|
}
|
||||||
|
all_posters.append(payload)
|
||||||
|
|
||||||
|
return jsonify(posters)
|
||||||
|
Loading…
Reference in new issue