From 6dff57aaaa60b9aa48d86fe0f104849ec4ca6369 Mon Sep 17 00:00:00 2001 From: HipsterCat Date: Fri, 22 Mar 2019 10:13:28 +0100 Subject: [PATCH] Prepend feed base url when link is absolute (still not working with relative links tho) --- web/utils.py | 6 ++++++ web/views.py | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/web/utils.py b/web/utils.py index bb49ba2..8593bbd 100644 --- a/web/utils.py +++ b/web/utils.py @@ -67,6 +67,12 @@ def fetch_feed(feed, limit=10): author = False try: link = element.select(feed.link)[0]["href"] + if link and len(link) > 2 and link[0] == "/" and link[1] != "/": + # fixes issue #5 with relative link + # prepend base url + base_scheme = feed.url.split("://")[0] + base_url = feed.url.split("//")[-1].split("/")[0].split('?')[0] + link = base_scheme + "://" + base_url + link except Exception: link = False items.append({"title": title, "content": content, "pubDate": date, "author": author, "link": link}) diff --git a/web/views.py b/web/views.py index de50ba1..ae29e0d 100644 --- a/web/views.py +++ b/web/views.py @@ -6,12 +6,14 @@ from django.db.models import ObjectDoesNotExist from bs4 import BeautifulSoup import logging from urllib.parse import quote_plus, unquote_plus +import traceback +import sys # Create your views here. logger = logging.getLogger(__name__) - def iframe(request, encodedurl): + sys.setrecursionlimit(10000) try: url = unquote_plus(encodedurl) req = get_url(url) @@ -59,7 +61,7 @@ def iframe(request, encodedurl): html = final_html except Exception as e: - logger.debug(e) + traceback.print_exc() return HttpResponse("An error has occured", content_type=500) return HttpResponse(html, content_type=content_type)