From 34579bd1518a5d3859ed97706b50ae494f932d0b Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 5 Aug 2018 13:55:48 +0200 Subject: [PATCH] Tweak OpenGraph --- templates/utils.html | 2 ++ utils/opengraph.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/utils.html b/templates/utils.html index 8b15a1a..3659366 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -77,6 +77,7 @@ {% if meta and meta.og_metadata and obj | has_type('Note') %} {% for og in meta.og_metadata %} +{% if og.url %}
@@ -87,6 +88,7 @@ {{ og.site_name }}
+{% endif %} {% endfor %} {% endif %} diff --git a/utils/opengraph.py b/utils/opengraph.py index 87ffa5e..30c752b 100644 --- a/utils/opengraph.py +++ b/utils/opengraph.py @@ -42,4 +42,11 @@ def fetch_og_metadata(user_agent, links): r = requests.get(l, headers={"User-Agent": user_agent}, timeout=15) r.raise_for_status() htmls.append(r.text) - return [dict(opengraph.OpenGraph(html=html)) for html in htmls] + + res = [] + for html in htmls: + data = dict(opengraph.OpenGraph(html=html)) + if data.get("url"): + res.append(data) + + return res