Skip to content

Commit

Permalink
return status code in MakeHTMLRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
TEMtheLEM committed May 15, 2024
1 parent fcde7ea commit ac4a11e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def wikipedia():
query = request.args.get("q", "").strip()
else:
query = request.form.get("q", "").strip()
response = helpers.makeHTMLRequest(f"https://wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&titles={quote(query)}&pithumbsize=500", is_wiki=True)
response, _ = helpers.makeHTMLRequest(f"https://wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&titles={quote(query)}&pithumbsize=500", is_wiki=True)
return json.loads(response.text)


Expand All @@ -166,6 +166,7 @@ def api():
app.logger.error(e)
return jsonify({"error": "An error occurred while processing the request"}), 500


@app.route("/img_proxy")
def img_proxy():
# Get the URL of the image to proxy
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def makeHTMLRequest(url: str, is_google=False, is_wiki=False, is_piped=False):
content = None if html.status_code != 200 else BeautifulSoup(html.text, "lxml")

# Return the BeautifulSoup object
return (content, 200)
return (content, html.status_code)

# search highlights
def highlight_query_words(string, query):
Expand Down
2 changes: 1 addition & 1 deletion src/torrent_sites/nyaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def search(query, catagory="all"):
if catagory == "ignore":
return []

soup = helpers.makeHTMLRequest(f"https://{NYAA_DOMAIN}/?f=0&q={quote(query)}{catagory}")
soup, response_code = helpers.makeHTMLRequest(f"https://{NYAA_DOMAIN}/?f=0&q={quote(query)}{catagory}")
results = []
for torrent in soup.select(".default, .success, .danger"):
list_of_tds = torrent.find_all("td")
Expand Down
2 changes: 1 addition & 1 deletion src/torrent_sites/rutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def search(query, catagory="all"):


url = f"https://{RUTOR_DOMAIN}/search/{quote(query)}{catagory}"
html = helpers.makeHTMLRequest(url)
html, response_code = helpers.makeHTMLRequest(url)
results = []

for torrent in html.select(".gai, .tum"):
Expand Down
2 changes: 1 addition & 1 deletion src/torrent_sites/torrentgalaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def search(query, catagory="all"):
catagory = get_catagory_code(catagory)
if catagory == "ignore":
return []
soup = helpers.makeHTMLRequest(f"https://{TORRENTGALAXY_DOMAIN}/torrents.php?search={quote(query)}{catagory}#results")
soup, response_code = helpers.makeHTMLRequest(f"https://{TORRENTGALAXY_DOMAIN}/torrents.php?search={quote(query)}{catagory}#results")

result_divs = soup.findAll("div", {"class": "tgxtablerow"})
title = [div.find("div", {"id": "click"}) for div in result_divs]
Expand Down
2 changes: 1 addition & 1 deletion src/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def videoResults(query) -> Response:
api = args.get("api", "false")

# grab & format webpage
soup = makeHTMLRequest(f"https://{PIPED_INSTANCE_API}/search?q={quote(query)}&filter=all", is_piped=True)
soup, response_code = makeHTMLRequest(f"https://{PIPED_INSTANCE_API}/search?q={quote(query)}&filter=all", is_piped=True)
data = json.loads(soup.text)

# retrieve links
Expand Down

0 comments on commit ac4a11e

Please sign in to comment.