Fix error where some fact check pages would fail to load

Signed-off-by: Skylar "The Cobra" Widulski <cobra@vern.cc>
This commit is contained in:
Skylar "The Cobra" Widulski 2023-01-13 00:58:28 -05:00
parent 25cd2d956d
commit 0a206c2ea1
Signed by: cobra
GPG Key ID: 4FD8F812083FF6F9
2 changed files with 45 additions and 3 deletions

13
main.py
View File

@ -189,14 +189,18 @@ def fact_check(path):
for div in article.select("div"): div.decompose()
for script in article.select("script"): script.decompose()
article.find("section").decompose()
if article.find("section") != None:
article.find("section").decompose()
for a in article.select("p a:has(img)"):
a["href"] = re.sub(r"^(.*)$", r"/proxy/?url=\1", a["href"])
article = re.sub(r"(src=\")", r"\1/proxy/?url=", str(article))
rating.find("svg").decompose()
rating.find("img").decompose()
if rating != None:
rating.find("svg").decompose()
rating.find("img").decompose()
else:
rating = ''
# Author bio
author_bio = soup.select("div.author_bio p")[0].text
@ -470,6 +474,9 @@ def route_proxy():
if url.startswith("https://mediaproxy.snopes.com/") or url.startswith("https://media.snopes.com/") or url.startswith("https://www.snopes.com/"):
data = requests.get(url)
return Response(data.content, content_type=data.headers["content-type"])
elif url.startswith("/") and not url.startswith("//"):
data = requests.get("https://www.snopes.com" + url)
return Response(data.content, content_type=data.headers["content-type"])
else:
return Response(render_template("400.html"), status=400)
else:

35
templates/429.html Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>429 - Suds</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/favicon.png') }}">
</head>
<body>
<ul style="display:flex;justify-content:space-between;list-style-type:none;padding-left:0px;align-items:center;">
<li><a href="/"><img style="display:inline" src="{{ url_for('static', filename='img/logo.png') }}" height=100px></a></li>
<li><a href="/latest/">Latest</a></li>
<li><a href="/top/">Top</a></li>
<li><a href="/fact-check/">Fact Checks</a></li>
<li><a href="/collections/">Collections</a></li>
<li><a href="/news/">News</a></li>
<li><a href="/sitemap/">Archives</a></li>
<li><a href="/random/">Random</a></li>
<li>
<form style="align:right" action="/search/" method="get">
<input type=text" name="q" placeholder="Search Suds">
<input type="submit" value="Go">
</form>
</li>
</ul>
<hr>
<center>
<h1 style="font-size:10em;line-height:0em;">429</h1>
<p>Too many requests</p>
</center>
<hr>
<center><p><a href="http://git.vern.cc/cobra/suds">Source code</a></p></center>
</body>
</html>