forked from rDrama/rDrama
1
0
Fork 0
Aevann1 2021-09-27 22:26:34 +02:00
parent b66b7ea56f
commit dcd93cf03e
2 changed files with 6 additions and 17 deletions

View File

@ -244,7 +244,7 @@ def award_post(pid, v):
g.db.add(post.author)
g.db.commit()
if request.referrer: return redirect(request.referrer)
if len(request.referrer) > 1: return redirect(request.referrer)
else: return redirect("/")

View File

@ -370,29 +370,18 @@ def edit_post(pid, v):
def get_post_title(v):
url = request.values.get("url", None)
if not url:
return abort(400)
if not url: return abort(400)
#mimic chrome browser agent
headers = {"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"}
try:
x = requests.get(url, headers=headers)
except BaseException:
return {"error": "Could not reach page"}, 400
if not x.status_code == 200:
return {"error": f"Page returned {x.status_code}"}, x.status_code
try: x = requests.get(url, headers=headers)
except BaseException: return {"error": "Could not reach page"}, 400
if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code
try:
soup = BeautifulSoup(x.content, 'html.parser')
data = {"url": url,
"title": soup.find('title').string
}
return data
return {"url": url, "title": soup.find('title').string}
except BaseException:
return {"error": f"Could not find a title"}, 400