g
This commit is contained in:
parent
e4c4c93a1f
commit
b8ea79408c
2 changed files with 6 additions and 17 deletions
|
@ -244,7 +244,7 @@ def award_post(pid, v):
|
||||||
g.db.add(post.author)
|
g.db.add(post.author)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
if request.referrer: return redirect(request.referrer)
|
if len(request.referrer) > 1: return redirect(request.referrer)
|
||||||
else: return redirect("/")
|
else: return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -370,29 +370,18 @@ def edit_post(pid, v):
|
||||||
def get_post_title(v):
|
def get_post_title(v):
|
||||||
|
|
||||||
url = request.values.get("url", None)
|
url = request.values.get("url", None)
|
||||||
if not url:
|
if not url: return abort(400)
|
||||||
return abort(400)
|
|
||||||
|
|
||||||
#mimic chrome browser agent
|
#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"}
|
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:
|
try: x = requests.get(url, headers=headers)
|
||||||
x = requests.get(url, headers=headers)
|
except BaseException: return {"error": "Could not reach page"}, 400
|
||||||
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
|
|
||||||
|
|
||||||
|
if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code
|
||||||
|
|
||||||
try:
|
try:
|
||||||
soup = BeautifulSoup(x.content, 'html.parser')
|
soup = BeautifulSoup(x.content, 'html.parser')
|
||||||
|
return {"url": url, "title": soup.find('title').string}
|
||||||
data = {"url": url,
|
|
||||||
"title": soup.find('title').string
|
|
||||||
}
|
|
||||||
|
|
||||||
return data
|
|
||||||
except BaseException:
|
except BaseException:
|
||||||
return {"error": f"Could not find a title"}, 400
|
return {"error": f"Could not find a title"}, 400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue