mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +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
|
||||
|
||||
global url_uztracker
|
||||
global up
|
||||
url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
||||
response = requests.get(url_uztracker) # get da content from da url
|
||||
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
|
||||
try:
|
||||
response = requests.get(url_uztracker) # get da content from da url
|
||||
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):
|
||||
if up:
|
||||
search_url = url_uztracker + search
|
||||
if debug:
|
||||
print(search_url)
|
||||
@@ -44,8 +53,12 @@ def scrape_uztracker(search, debug):
|
||||
if result:
|
||||
print(f"Failed to fetch {search_url}: {e}")
|
||||
return None
|
||||
else:
|
||||
print("Error: Uztracker down")
|
||||
return None, None
|
||||
|
||||
def get_post_title(post_url, debug):
|
||||
if up:
|
||||
response = requests.get(post_url)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
maintitle = soup.find(class_='tt-text')
|
||||
@@ -54,9 +67,13 @@ def get_post_title(post_url, debug):
|
||||
else:
|
||||
if debug:
|
||||
print("Program not found")
|
||||
else:
|
||||
print("Error: Uztracker down")
|
||||
return None
|
||||
|
||||
|
||||
def get_magnet_link(post_url, debug):
|
||||
if up:
|
||||
try:
|
||||
response = requests.get(post_url)
|
||||
response.raise_for_status()
|
||||
@@ -72,6 +89,9 @@ def get_magnet_link(post_url, debug):
|
||||
except requests.RequestException as e:
|
||||
if debug:
|
||||
print(f"Failed to fetch {post_url}: {e}")
|
||||
else:
|
||||
print("Error: Uztracker down")
|
||||
return None
|
||||
|
||||
# What x and x.startswith('magnet:') Does
|
||||
# x - check if x exists (not None/empty)
|
||||
|
||||
Reference in New Issue
Block a user