forked from Ponysearch/Ponysearch
[fix] hackernews keyerror problem
This commit is contained in:
parent
af071121de
commit
efada7cba2
1 changed files with 4 additions and 4 deletions
|
@ -71,17 +71,17 @@ def response(resp):
|
||||||
|
|
||||||
for hit in data["hits"]:
|
for hit in data["hits"]:
|
||||||
object_id = hit["objectID"]
|
object_id = hit["objectID"]
|
||||||
points = hit["points"] or 0
|
points = hit.get("points") or 0
|
||||||
num_comments = hit["num_comments"] or 0
|
num_comments = hit.get("num_comments") or 0
|
||||||
|
|
||||||
metadata = ""
|
metadata = ""
|
||||||
if points != 0 or num_comments != 0:
|
if points != 0 or num_comments != 0:
|
||||||
metadata = f"{gettext('points')}: {points}" f" | {gettext('comments')}: {num_comments}"
|
metadata = f"{gettext('points')}: {points}" f" | {gettext('comments')}: {num_comments}"
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
"title": hit["title"] or f"{gettext('author')}: {hit['author']}",
|
"title": hit.get("title") or f"{gettext('author')}: {hit['author']}",
|
||||||
"url": f"https://news.ycombinator.com/item?id={object_id}",
|
"url": f"https://news.ycombinator.com/item?id={object_id}",
|
||||||
"content": hit["url"] or hit["comment_text"] or hit["story_text"] or "",
|
"content": hit.get("url") or hit.get("comment_text") or hit.get("story_text") or "",
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"author": hit["author"],
|
"author": hit["author"],
|
||||||
"publishedDate": datetime.utcfromtimestamp(hit["created_at_i"]),
|
"publishedDate": datetime.utcfromtimestamp(hit["created_at_i"]),
|
||||||
|
|
Loading…
Reference in a new issue