Prepend feed base url when link is absolute (still not working with relative links tho)

This commit is contained in:
Amazed 2019-03-22 10:13:28 +01:00
parent 64f6e33b34
commit 6dff57aaaa
2 changed files with 10 additions and 2 deletions

View File

@ -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})

View File

@ -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)