diff --git a/main.py b/main.py index 910dfd2..3e3b5d0 100644 --- a/main.py +++ b/main.py @@ -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: diff --git a/templates/429.html b/templates/429.html new file mode 100644 index 0000000..859aa45 --- /dev/null +++ b/templates/429.html @@ -0,0 +1,35 @@ + + + + 429 - Suds + + + + + + + +
+
+

429

+

Too many requests

+
+
+

Source code

+ +