mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
Implement debug mode for scraping and GUI interactions
This commit is contained in:
@@ -6,9 +6,10 @@ url_uztracker = "https://uztracker.net/tracker.php?nm=" # placeholder url for no
|
|||||||
response = requests.get(url_uztracker) # 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(search):
|
def scrape_uztracker(search, debug):
|
||||||
search_url = url_uztracker + search
|
search_url = url_uztracker + search
|
||||||
print(search_url)
|
if debug:
|
||||||
|
print(search_url)
|
||||||
result = False
|
result = False
|
||||||
global results
|
global results
|
||||||
global resulttitles
|
global resulttitles
|
||||||
@@ -34,24 +35,28 @@ def scrape_uztracker(search):
|
|||||||
return resulttitles, results
|
return resulttitles, results
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
print(f'No Results found for "{search}"')
|
if debug:
|
||||||
|
print(f'No Results found for "{search}"')
|
||||||
|
# add popup in gui for no result
|
||||||
return
|
return
|
||||||
|
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"Failed to fetch {search_url}: {e}")
|
if result:
|
||||||
|
print(f"Failed to fetch {search_url}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_post_title(post_url):
|
def get_post_title(post_url, debug):
|
||||||
response = requests.get(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:
|
||||||
return maintitle.text
|
return maintitle.text
|
||||||
else:
|
else:
|
||||||
print("Program not found")
|
if debug:
|
||||||
|
print("Program not found")
|
||||||
|
|
||||||
|
|
||||||
def get_magnet_link(post_url):
|
def get_magnet_link(post_url, debug):
|
||||||
try:
|
try:
|
||||||
response = requests.get(post_url)
|
response = requests.get(post_url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -60,9 +65,11 @@ def get_magnet_link(post_url):
|
|||||||
if magnet_link:
|
if magnet_link:
|
||||||
return magnet_link['href']
|
return magnet_link['href']
|
||||||
else:
|
else:
|
||||||
print("Magnet Link not Found!")
|
if debug:
|
||||||
|
print("Magnet Link not Found!")
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"Failed to fetch {post_url}: {e}")
|
if debug:
|
||||||
|
print(f"Failed to fetch {post_url}: {e}")
|
||||||
|
|
||||||
# What x and x.startswith('magnet:') Does
|
# What x and x.startswith('magnet:') Does
|
||||||
# x - check if x exists (not None/empty)
|
# x - check if x exists (not None/empty)
|
||||||
|
|||||||
+21
-8
@@ -9,6 +9,12 @@ from core.downloading.download import start_client
|
|||||||
from core.downloading.download import add_magnet
|
from core.downloading.download import add_magnet
|
||||||
|
|
||||||
|
|
||||||
|
def state_debug(setting):
|
||||||
|
global debug
|
||||||
|
if setting is True:
|
||||||
|
debug = True
|
||||||
|
else:
|
||||||
|
debug = False
|
||||||
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global settings_action
|
global settings_action
|
||||||
@@ -62,15 +68,17 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
toolbar.setMovable(False)
|
toolbar.setMovable(False)
|
||||||
|
|
||||||
def settings_dialog(self):
|
def settings_dialog(self):
|
||||||
print("Settings dialog opened")
|
if debug:
|
||||||
|
print("Settings dialog opened")
|
||||||
dialog = QDialog(self)
|
dialog = QDialog(self)
|
||||||
dialog.setWindowTitle("test")
|
dialog.setWindowTitle("Settings")
|
||||||
dialog.setFixedSize(400, 300)
|
dialog.setFixedSize(400, 300)
|
||||||
|
|
||||||
|
|
||||||
dialog.setLayout(QVBoxLayout())
|
dialog.setLayout(QVBoxLayout())
|
||||||
label = QLabel("This is a settings dialog.")
|
label = QLabel("This is a settings dialog.")
|
||||||
QtWidgets.QPushButton("Close", clicked=dialog.close)
|
QtWidgets.QPushButton("Close", clicked=dialog.close)
|
||||||
|
# close button
|
||||||
dialog.layout().addWidget(label)
|
dialog.layout().addWidget(label)
|
||||||
dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
dialog.layout().addWidget(QtWidgets.QPushButton("Close", clicked=dialog.close))
|
||||||
|
|
||||||
@@ -98,10 +106,13 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
def download_selected(self):
|
def download_selected(self):
|
||||||
item = self.softwareList.currentItem()
|
item = self.softwareList.currentItem()
|
||||||
if item is not None:
|
if item is not None:
|
||||||
print(f"Downloading {self.softwareList.currentItem().text()}")
|
if debug:
|
||||||
|
print(f"Downloading {self.softwareList.currentItem().text()}")
|
||||||
self.get_item_index(self.softwareList.currentItem().text(), self.postnames, self.postlinks)
|
self.get_item_index(self.softwareList.currentItem().text(), self.postnames, self.postlinks)
|
||||||
else:
|
else:
|
||||||
print("No item selected for download.")
|
if debug:
|
||||||
|
print("No item selected for download.")
|
||||||
|
# add gui notification for no item selected
|
||||||
|
|
||||||
|
|
||||||
def get_selected_item(self):
|
def get_selected_item(self):
|
||||||
@@ -114,11 +125,12 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
def return_pressed(self):
|
def return_pressed(self):
|
||||||
search_text = self.searchbar.text()
|
search_text = self.searchbar.text()
|
||||||
self.postnames, self.postlinks = scrape_uztracker(search_text)
|
self.postnames, self.postlinks = scrape_uztracker(search_text, debug)
|
||||||
self.softwareList.clear()
|
self.softwareList.clear()
|
||||||
if self.postnames:
|
if self.postnames:
|
||||||
self.softwareList.addItems(self.postnames)
|
self.softwareList.addItems(self.postnames)
|
||||||
print("User searched for:", search_text)
|
if debug:
|
||||||
|
print("User searched for:", search_text)
|
||||||
|
|
||||||
|
|
||||||
def get_item_index(self, item, list, listlinks):
|
def get_item_index(self, item, list, listlinks):
|
||||||
@@ -126,7 +138,8 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if 0 <= position < len(listlinks): # note for myself: py starts counting at 0; check if number is not negative, check if number is not more than list length.
|
if 0 <= position < len(listlinks): # 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/" + listlinks[position].lstrip("./")
|
selected = "https://uztracker.net/" + listlinks[position].lstrip("./")
|
||||||
post_url = selected
|
post_url = selected
|
||||||
print(selected)
|
if debug:
|
||||||
selected_magnet = get_magnet_link(selected)
|
print("Selected URL: ", selected)
|
||||||
|
selected_magnet = get_magnet_link(selected, debug)
|
||||||
start_client()
|
start_client()
|
||||||
add_magnet(selected_magnet)
|
add_magnet(selected_magnet)
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
from core.ui.gui import MainWindow
|
from core.ui.gui import MainWindow
|
||||||
|
from core.ui.gui import state_debug
|
||||||
from PySide6 import QtWidgets
|
from PySide6 import QtWidgets
|
||||||
import qdarktheme
|
import qdarktheme
|
||||||
import darkdetect
|
import darkdetect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
debug = True
|
||||||
|
|
||||||
def run_gui():
|
def run_gui():
|
||||||
|
state_debug(debug)
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
if darkdetect.isDark:
|
if darkdetect.isDark:
|
||||||
app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
|
app.setStyleSheet(qdarktheme.load_stylesheet("dark"))
|
||||||
|
|||||||
Reference in New Issue
Block a user