mirror of
https://git.wownero.com/lza_menace/suchwow.git
synced 2024-08-15 01:03:19 +00:00
add simple api route to list posts
This commit is contained in:
parent
8c014e1292
commit
65414c4e00
2 changed files with 29 additions and 1 deletions
|
@ -8,7 +8,7 @@ from flask import render_template, flash, url_for
|
||||||
from flask_session import Session
|
from flask_session import Session
|
||||||
from suchwow import config
|
from suchwow import config
|
||||||
from suchwow.models import Post, Profile, Comment, Notification, db, Moderator
|
from suchwow.models import Post, Profile, Comment, Notification, db, Moderator
|
||||||
from suchwow.routes import auth, comment, post, profile, leaderboard
|
from suchwow.routes import auth, comment, post, profile, leaderboard, api
|
||||||
from suchwow.utils.decorators import login_required, moderator_required
|
from suchwow.utils.decorators import login_required, moderator_required
|
||||||
from suchwow.utils.helpers import post_webhook
|
from suchwow.utils.helpers import post_webhook
|
||||||
from suchwow.reddit import make_post
|
from suchwow.reddit import make_post
|
||||||
|
@ -26,6 +26,7 @@ app.register_blueprint(auth.bp)
|
||||||
app.register_blueprint(profile.bp)
|
app.register_blueprint(profile.bp)
|
||||||
app.register_blueprint(comment.bp)
|
app.register_blueprint(comment.bp)
|
||||||
app.register_blueprint(leaderboard.bp)
|
app.register_blueprint(leaderboard.bp)
|
||||||
|
app.register_blueprint(api.bp)
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|
27
suchwow/routes/api.py
Normal file
27
suchwow/routes/api.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from flask import jsonify, Blueprint, url_for
|
||||||
|
from suchwow.models import Post
|
||||||
|
from suchwow import wownero
|
||||||
|
|
||||||
|
|
||||||
|
bp = Blueprint("api", "api")
|
||||||
|
|
||||||
|
@bp.route("/api/list")
|
||||||
|
def api_list():
|
||||||
|
all_posts = []
|
||||||
|
posts = Post.select().where(Post.approved==True)
|
||||||
|
for post in posts:
|
||||||
|
wallet = wownero.Wallet()
|
||||||
|
if wallet.connected:
|
||||||
|
address = wallet.get_address(account=post.account_index)
|
||||||
|
else:
|
||||||
|
address = ''
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
'image': url_for('post.uploaded_file', filename=post.image_name, _external=True),
|
||||||
|
'submitter': post.submitter,
|
||||||
|
'address': address,
|
||||||
|
'title': post.title,
|
||||||
|
'href': url_for('post.read', id=post.id, _external=True)
|
||||||
|
}
|
||||||
|
all_posts.append(payload)
|
||||||
|
return jsonify(all_posts)
|
Loading…
Reference in a new issue