rename meta attributes, add 2ch.hk support, version bump

This commit is contained in:
2019-09-05 12:59:08 -04:00
parent 2890222c4d
commit 9447463e56
6 changed files with 137 additions and 45 deletions

View File

@@ -3,31 +3,20 @@ import re
LINK_RE = re.compile(r"(https?://[\w\-_.]+\.[a-z]{2,4}([^\s<'\"]*|$))")
def post_process(thing, board, helper):
thing["v"] = 1.1
thing["_id"] = int(thing["no"])
def post_process(item, board, helper):
item["_v"] = 1.2
item["_id"] = helper.item_id(item)
thing["board"] = board
thing["chan"] = helper.db_id
item["_board"] = board
item["_chan"] = helper.db_id
if "com" in thing and thing["com"]:
thing["urls"] = get_links_from_body(thing["com"])
elif "sub" in thing and thing["sub"]:
thing["urls"] = get_links_from_body(thing["sub"])
if "fsize" in thing and thing["fsize"]:
url = helper.image_url(board, thing["tim"], thing["ext"])
if "urls" in thing:
thing["urls"].append(url)
else:
thing["urls"] = [url]
if "urls" not in thing:
thing["urls"] = []
item["_urls"] = helper.item_urls(item, board)
return thing
return item
def get_links_from_body(body):
result = set()
result = []
body = body \
.replace("<wbr>", "") \
@@ -37,9 +26,9 @@ def get_links_from_body(body):
for match in LINK_RE.finditer(body):
url = match.group(1)
if is_external(url):
result.add(url)
result.append(url)
return list(result)
return result
def is_external(url):