mirror of
https://github.com/simon987/chan_feed.git
synced 2025-12-16 05:49:01 +00:00
rename meta attributes, add 2ch.hk support, version bump
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user