Restructure Functions to Return and not Print, made maintitle available in Main.py

This commit is contained in:
Vxrtrauter
2025-06-28 02:52:16 +02:00
parent b8b22cecca
commit 84c54870ab
2 changed files with 42 additions and 25 deletions
+31 -25
View File
@@ -1,13 +1,14 @@
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
search = input("Enter the name of the program you want to search for: ") global url_uztracker
url = "https://uztracker.net/tracker.php?nm=" # placeholder url for now url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
response = requests.get(url) # 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
def scrape_uztracker(): def scrape_uztracker():
search_url = url + search search = input("Enter the name of the program you want to search for: ")
search_url = url_uztracker + search
print(search_url) print(search_url)
result = False result = False
global results global results
@@ -30,36 +31,37 @@ def scrape_uztracker():
print(f'No Results found for "{search}"') print(f'No Results found for "{search}"')
return return
select_program() selection = input("Enter the Number of the Program you want to download: ")
return soup
try:
index = int(selection) - 1
if 0 <= index < len(results): # note for myself: py starts counting at 0; check if number is not negative, check if number is not more than list length.
selected = "https://uztracker.net/" + results[index].lstrip("./")
post_url = selected
return selected
else:
print("Invalid Selection.")
except ValueError:
print(Exception)
return
except requests.RequestException as e: except requests.RequestException as e:
print(f"Failed to fetch {search_url}: {e}") print(f"Failed to fetch {search_url}: {e}")
return None return None
def get_post_title(post_url): def get_post_title(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')
if maintitle: if maintitle:
print(maintitle.text) return maintitle.text
else: else:
print("Program not found") print("Program not found")
def select_program():
selection = input("Enter the Number of the Program you want to download: ")
try:
index = int(selection) - 1
if 0 <= index < len(results): # note for myself: py starts counting at 0; check if number is not negative, check if number is not more than list length.
selected = "https://uztracker.net/" + results[index].lstrip("./")
post_url = selected
get_magnet_link(post_url)
else:
print("Invalid Selection.")
except ValueError:
print(Exception)
return
def get_magnet_link(post_url): def get_magnet_link(post_url):
try: try:
response = requests.get(post_url) response = requests.get(post_url)
@@ -67,7 +69,7 @@ def get_magnet_link(post_url):
soup = BeautifulSoup(response.text, 'html.parser') soup = BeautifulSoup(response.text, 'html.parser')
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:')) magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:'))
if magnet_link: if magnet_link:
print("Magnet Link found:", magnet_link['href']) return magnet_link['href']
else: else:
print("Magnet Link not Found!") print("Magnet Link not Found!")
except requests.RequestException as e: except requests.RequestException as e:
@@ -83,6 +85,10 @@ def get_magnet_link(post_url):
if __name__ == "__main__": if __name__ == "__main__":
soup = scrape_uztracker() selected = scrape_uztracker()
maintitle = get_post_title(selected)
magnetlink = get_magnet_link(selected)
print(maintitle)
print(magnetlink)
+11
View File
@@ -1,3 +1,14 @@
import core.gui as gui import core.gui as gui
from core.uztracker_scraper import scrape_uztracker, get_post_title
post_url = scrape_uztracker()
if post_url:
maintitle = get_post_title(post_url)
print(maintitle)