mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
updated get_magnet_link function
This commit is contained in:
+17
-12
@@ -1,5 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
import curses
|
||||||
|
|
||||||
search = input("Enter the name of the program you want to search for: ")
|
search = input("Enter the name of the program you want to search for: ")
|
||||||
url = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
url = "https://uztracker.net/tracker.php?nm=" # placeholder url for now
|
||||||
@@ -29,20 +30,25 @@ def scrape_uztracker():
|
|||||||
print(f"Failed to fetch {search_url}: {e}")
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_post_title():
|
def get_post_title(soup):
|
||||||
maintitle = soup.find(class_='tt-text')
|
maintitle = soup.find(class_='tt-text')
|
||||||
if maintitle:
|
if maintitle:
|
||||||
print("Program found:", maintitle.text)
|
print("Program found:", maintitle.text)
|
||||||
else:
|
else:
|
||||||
print("Program not found")
|
print("Program not found")
|
||||||
|
|
||||||
|
def get_magnet_link(post_url="https://uztracker.net/viewtopic.php?t=23897"):
|
||||||
def get_magnet_link():
|
try:
|
||||||
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:')) # credits to claude for helping me with lambda.
|
response = requests.get(post_url)
|
||||||
if magnet_link:
|
response.raise_for_status()
|
||||||
print("Magnet Link found:", magnet_link['href'])
|
soup = BeautifulSoup(response.text, 'html.parser')
|
||||||
else:
|
magnet_link = soup.find('a', href=lambda x: x and x.startswith('magnet:'))
|
||||||
print("Magnet Link not Found!")
|
if magnet_link:
|
||||||
|
print("Magnet Link found:", magnet_link['href'])
|
||||||
|
else:
|
||||||
|
print("Magnet Link not Found!")
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f"Failed to fetch {post_url}: {e}")
|
||||||
|
|
||||||
# What x and x.startswith('magnet:') Does
|
# What x and x.startswith('magnet:') Does
|
||||||
|
|
||||||
@@ -52,8 +58,7 @@ def get_magnet_link():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
soup = scrape_uztracker()
|
soup = scrape_uztracker()
|
||||||
|
if soup:
|
||||||
if response.status_code == 200:
|
get_post_title(soup)
|
||||||
get_post_title()
|
get_magnet_link()
|
||||||
get_magnet_link()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user