mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
Restructure Functions to Return and not Print, made maintitle available in Main.py
This commit is contained in:
+31
-25
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user