remove umbrella
This commit is contained in:
parent
087d2f9442
commit
359294e166
1 changed files with 35 additions and 53 deletions
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from flask import abort, jsonify, request
|
from flask import abort, jsonify, request
|
||||||
|
|
||||||
from stacosys.interface import app
|
from stacosys.interface import app
|
||||||
from stacosys.model.comment import Comment
|
from stacosys.model.comment import Comment
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/ping", methods=["GET"])
|
@app.route("/ping", methods=["GET"])
|
||||||
def ping():
|
def ping():
|
||||||
return "OK"
|
return "OK"
|
||||||
|
@ -17,61 +17,43 @@ def ping():
|
||||||
|
|
||||||
@app.route("/comments", methods=["GET"])
|
@app.route("/comments", methods=["GET"])
|
||||||
def query_comments():
|
def query_comments():
|
||||||
|
|
||||||
comments = []
|
comments = []
|
||||||
try:
|
token = request.args.get("token", "")
|
||||||
token = request.args.get("token", "")
|
if token != app.config.get("SITE_TOKEN"):
|
||||||
if token != app.config.get("SITE_TOKEN"):
|
abort(401)
|
||||||
abort(401)
|
url = request.args.get("url", "")
|
||||||
|
|
||||||
url = request.args.get("url", "")
|
logger.info("retrieve comments for url %s" % (url))
|
||||||
|
for comment in (
|
||||||
logger.info("retrieve comments for url %s" % (url))
|
Comment.select(Comment)
|
||||||
for comment in (
|
.where((Comment.url == url) & (Comment.published.is_null(False)))
|
||||||
Comment.select(Comment)
|
.order_by(+Comment.published)
|
||||||
.where((Comment.url == url) & (Comment.published.is_null(False)))
|
):
|
||||||
.order_by(+Comment.published)
|
d = {
|
||||||
):
|
"author": comment.author_name,
|
||||||
d = {
|
"content": comment.content,
|
||||||
"author": comment.author_name,
|
"avatar": comment.author_gravatar,
|
||||||
"content": comment.content,
|
"date": comment.published.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
"avatar": comment.author_gravatar,
|
}
|
||||||
"date": comment.published.strftime("%Y-%m-%d %H:%M:%S"),
|
if comment.author_site:
|
||||||
}
|
d["site"] = comment.author_site
|
||||||
if comment.author_site:
|
logger.debug(d)
|
||||||
d["site"] = comment.author_site
|
comments.append(d)
|
||||||
logger.debug(d)
|
return jsonify({"data": comments})
|
||||||
comments.append(d)
|
|
||||||
r = jsonify({"data": comments})
|
|
||||||
r.status_code = 200
|
|
||||||
except Exception:
|
|
||||||
logger.warn("bad request")
|
|
||||||
r = jsonify({"data": []})
|
|
||||||
r.status_code = 400
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/comments/count", methods=["GET"])
|
@app.route("/comments/count", methods=["GET"])
|
||||||
def get_comments_count():
|
def get_comments_count():
|
||||||
try:
|
token = request.args.get("token", "")
|
||||||
token = request.args.get("token", "")
|
if token != app.config.get("SITE_TOKEN"):
|
||||||
if token != app.config.get("SITE_TOKEN"):
|
abort(401)
|
||||||
abort(401)
|
url = request.args.get("url", "")
|
||||||
|
if url:
|
||||||
url = request.args.get("url", "")
|
count = (
|
||||||
if url:
|
Comment.select(Comment)
|
||||||
count = (
|
.where((Comment.url == url) & (Comment.published.is_null(False)))
|
||||||
Comment.select(Comment)
|
.count()
|
||||||
.where((Comment.url == url) & (Comment.published.is_null(False)))
|
)
|
||||||
.count()
|
else:
|
||||||
)
|
count = Comment.select(Comment).where(Comment.publishd.is_null(False)).count()
|
||||||
else:
|
return jsonify({"count": count})
|
||||||
count = (
|
|
||||||
Comment.select(Comment).where(Comment.published.is_null(False)).count()
|
|
||||||
)
|
|
||||||
r = jsonify({"count": count})
|
|
||||||
r.status_code = 200
|
|
||||||
except Exception:
|
|
||||||
r = jsonify({"count": 0})
|
|
||||||
r.status_code = 200
|
|
||||||
return r
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue