mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
Refactor uztracker scraper to handle site availability checks and improve error handling
This commit is contained in:
@@ -2,11 +2,20 @@ import requests
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
global url_uztracker
|
global url_uztracker
|
||||||
|
global up
|
||||||
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
||||||
|
try:
|
||||||
response = requests.get(url_uztracker) # get da content from da url
|
response = requests.get(url_uztracker) # get da content from da url
|
||||||
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
|
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
|
||||||
|
up = True
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"\nRequest Exception on {url_uztracker}:")
|
||||||
|
print(e)
|
||||||
|
print("\nIs the Site down?")
|
||||||
|
up = False
|
||||||
|
|
||||||
def scrape_uztracker(search, debug):
|
def scrape_uztracker(search, debug):
|
||||||
|
if up:
|
||||||
search_url = url_uztracker + search
|
search_url = url_uztracker + search
|
||||||
if debug:
|
if debug:
|
||||||
print(search_url)
|
print(search_url)
|
||||||
@@ -44,8 +53,12 @@ def scrape_uztracker(search, debug):
|
|||||||
if result:
|
if result:
|
||||||
print(f"Failed to fetch {search_url}: {e}")
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
return None
|
return None
|
||||||
|
else:
|
||||||
|
print("Error: Uztracker down")
|
||||||
|
return None, None
|
||||||
|
|
||||||
def get_post_title(post_url, debug):
|
def get_post_title(post_url, debug):
|
||||||
|
if up:
|
||||||
response = requests.get(post_url)
|
response = requests.get(post_url)
|
||||||
soup = BeautifulSoup(response.text, 'html.parser')
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
maintitle = soup.find(class_='tt-text')
|
maintitle = soup.find(class_='tt-text')
|
||||||
@@ -54,9 +67,13 @@ def get_post_title(post_url, debug):
|
|||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print("Program not found")
|
print("Program not found")
|
||||||
|
else:
|
||||||
|
print("Error: Uztracker down")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_magnet_link(post_url, debug):
|
def get_magnet_link(post_url, debug):
|
||||||
|
if up:
|
||||||
try:
|
try:
|
||||||
response = requests.get(post_url)
|
response = requests.get(post_url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -72,6 +89,9 @@ def get_magnet_link(post_url, debug):
|
|||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
if debug:
|
if debug:
|
||||||
print(f"Failed to fetch {post_url}: {e}")
|
print(f"Failed to fetch {post_url}: {e}")
|
||||||
|
else:
|
||||||
|
print("Error: Uztracker down")
|
||||||
|
return None
|
||||||
|
|
||||||
# What x and x.startswith('magnet:') Does
|
# What x and x.startswith('magnet:') Does
|
||||||
# x - check if x exists (not None/empty)
|
# x - check if x exists (not None/empty)
|
||||||
|
|||||||
Reference in New Issue
Block a user