Tweak the lookup and the OG metedata tasks

Now we don't fetch OG metadata for AP profile
This commit is contained in:
Thomas Sileo
2018-07-22 11:44:42 +02:00
parent a841efc9e8
commit a165e36303
4 changed files with 25 additions and 10 deletions

View File

@@ -1,8 +1,11 @@
import opengraph
import requests
from bs4 import BeautifulSoup
from little_boxes import activitypub as ap
from little_boxes.errors import NotAnActivityError
from little_boxes.urlutils import check_url
from little_boxes.urlutils import is_url_valid
from .lookup import lookup
def links_from_note(note):
@@ -10,7 +13,6 @@ def links_from_note(note):
for t in note.get("tag", []):
h = t.get("href")
if h:
# TODO(tsileo): fetch the URL for Actor profile, type=mention
tags_href.add(h)
links = set()
@@ -27,6 +29,15 @@ def fetch_og_metadata(user_agent, links):
htmls = []
for l in links:
check_url(l)
# Remove any AP actor from the list
try:
p = lookup(l)
if p.has_type(ap.ACTOR_TYPES):
continue
except NotAnActivityError:
pass
r = requests.get(l, headers={"User-Agent": user_agent}, timeout=15)
r.raise_for_status()
htmls.append(r.text)