mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
Add Search Results to Gui, Restructure Functions, Split Scrape and Select Function.
This commit is contained in:
+17
-2
@@ -2,10 +2,14 @@ from PySide6 import QtWidgets
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QLayoutItem, QLineEdit, QWidget, QVBoxLayout, QHBoxLayout, QListWidget, QListWidgetItem, QLabel, QPushButton
|
||||
import sys
|
||||
from uztracker_scraper import scrape_uztracker
|
||||
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
searchresults = []
|
||||
|
||||
self.setWindowTitle("Software Manager")
|
||||
self.setGeometry(100, 100, 800, 600)
|
||||
|
||||
@@ -27,7 +31,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
containerLayout.addWidget(self.searchbar)
|
||||
|
||||
containerLayout.addWidget(self.softwareList)
|
||||
self.softwareList.addItems(["Software A", "Software B", "Software C", "Software D"])
|
||||
self.softwareList.addItems(searchresults)
|
||||
|
||||
containerLayout.addWidget(self.button)
|
||||
self.button.clicked.connect(lambda: print(f"Downloading {self.softwareList.currentItem().text()}"))
|
||||
@@ -39,12 +43,23 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
|
||||
def return_pressed(self):
|
||||
search_text = self.searchbar.text()
|
||||
global searchresults
|
||||
self.searchresults = scrape_uztracker(search_text)
|
||||
self.softwareList.clear()
|
||||
if self.searchresults:
|
||||
self.softwareList.addItems(self.searchresults)
|
||||
print("User searched for:", search_text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
def run_gui():
|
||||
app = QtWidgets.QApplication([])
|
||||
|
||||
widget = MainWindow()
|
||||
widget.show()
|
||||
|
||||
sys.exit(app.exec())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_gui()
|
||||
|
||||
+28
-19
@@ -6,13 +6,15 @@ url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for no
|
||||
response = requests.get(url_uztracker) # get da content from da url
|
||||
soup = BeautifulSoup(response.content, 'html.parser') # create bs object
|
||||
|
||||
def scrape_uztracker():
|
||||
search = input("Enter the name of the program you want to search for: ")
|
||||
def scrape_uztracker(search):
|
||||
search_url = url_uztracker + search
|
||||
print(search_url)
|
||||
result = False
|
||||
global results
|
||||
global resulttitles
|
||||
results = []
|
||||
resulttitles = []
|
||||
|
||||
try:
|
||||
resultCount = 0
|
||||
response = requests.get(search_url)
|
||||
@@ -22,31 +24,20 @@ def scrape_uztracker():
|
||||
for link in links:
|
||||
if link.b:
|
||||
resultCount += 1
|
||||
print(f"Result found: ({resultCount}) {link.b.text} | {link['href']}")
|
||||
|
||||
# print(f"Result found: ({resultCount}) {link.b.text} | {link['href']}")
|
||||
results.append(link['href'])
|
||||
resulttitles.append(link.b.text)
|
||||
result = True
|
||||
|
||||
if result:
|
||||
return resulttitles
|
||||
|
||||
if not result:
|
||||
print(f'No Results found for "{search}"')
|
||||
return
|
||||
|
||||
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
|
||||
return selected
|
||||
else:
|
||||
print("Invalid Selection.")
|
||||
|
||||
|
||||
except ValueError:
|
||||
print(Exception)
|
||||
return
|
||||
|
||||
|
||||
except requests.RequestException as e:
|
||||
print(f"Failed to fetch {search_url}: {e}")
|
||||
@@ -61,6 +52,24 @@ def get_post_title(post_url):
|
||||
else:
|
||||
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
|
||||
return selected
|
||||
else:
|
||||
print("Invalid Selection.")
|
||||
|
||||
except ValueError:
|
||||
print(Exception)
|
||||
return
|
||||
|
||||
|
||||
def get_magnet_link(post_url):
|
||||
try:
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import core.gui as gui
|
||||
from core.uztracker_scraper import scrape_uztracker, get_post_title
|
||||
from core.uztracker_scraper import scrape_uztracker, get_post_title, get_magnet_link
|
||||
from core.gui import run_gui
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +15,9 @@ from core.uztracker_scraper import scrape_uztracker, get_post_title
|
||||
post_url = scrape_uztracker()
|
||||
if post_url:
|
||||
maintitle = get_post_title(post_url)
|
||||
magnetlink = get_magnet_link(post_url)
|
||||
print(maintitle)
|
||||
print(magnetlink)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user