mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 09:59:41 +02:00
a fuzzyfind demo works, use python -m core.interface.utils.fzhelper
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,21 +4,40 @@ import requests
|
||||
import re
|
||||
#from core.utils.general.logs import consoleLog
|
||||
|
||||
def scrape_steamrip_links():
|
||||
url = f"https://steamrip.com/games-list-page/"
|
||||
response = requests.get(url)
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
def scrape_steamrip_links(text = None):
|
||||
if text is None:
|
||||
url = f"https://steamrip.com/games-list-page/"
|
||||
response = requests.get(url)
|
||||
text = response.text
|
||||
|
||||
soup = BeautifulSoup(text, "html.parser")
|
||||
games = soup.find_all("li", class_="az-list-item")
|
||||
|
||||
if len(games) == 0:
|
||||
return []
|
||||
|
||||
links = []
|
||||
for gamehtml in games:
|
||||
for i, gamehtml in enumerate(games):
|
||||
if i == 0: print(gamehtml)
|
||||
link = gamehtml.find("a", href=lambda x: x and x.startswith("/"))
|
||||
links += re.findall('(?<=href=")[^"]*', link.__str__())
|
||||
|
||||
return links
|
||||
|
||||
# construct the list[dict[str,str]]
|
||||
|
||||
ret = []
|
||||
|
||||
for link in links:
|
||||
ret.append({"name" : link})
|
||||
|
||||
return ret
|
||||
|
||||
def offline_scrape_steamrip_links():
|
||||
text = ""
|
||||
with open("example.html", encoding = "utf-8") as f:
|
||||
text=f.read()
|
||||
|
||||
return scrape_steamrip_links(text)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(scrape_steamrip_links())
|
||||
print(offline_scrape_steamrip_links())
|
||||
@@ -1,5 +1,6 @@
|
||||
import fuzzyfinder
|
||||
from PySide6 import QtCore, QtWidgets, QtGui
|
||||
from sys import exit
|
||||
|
||||
class FuzzySearchWindow(QtWidgets.QWidget):
|
||||
"""
|
||||
@@ -20,9 +21,59 @@ class FuzzySearchWindow(QtWidgets.QWidget):
|
||||
|
||||
self.opts: list[dict[str, str]] = options
|
||||
|
||||
self.searchbox = QtWidgets.QTextEdit()
|
||||
self.searchbox = QtWidgets.QLineEdit()
|
||||
self.searchbox.placeholderText = "Search for a game"
|
||||
|
||||
self.table = QtWidgets.QTableWidget()
|
||||
self.table.setHorizontalHeader(self.opts[0].keys())
|
||||
headers = self.opts[1].keys()
|
||||
|
||||
print(headers)
|
||||
self.table.setColumnCount(len(headers))
|
||||
self.table.setHorizontalHeaderLabels(headers)
|
||||
|
||||
self.table.setRowCount(len(self.opts))
|
||||
for row_index, row_data in enumerate(self.opts):
|
||||
for col_index, key in enumerate(headers):
|
||||
value = row_data.get(key, "")[1:-1].replace("-", " ")
|
||||
item = QtWidgets.QTableWidgetItem(value)
|
||||
self.table.setItem(row_index, col_index, item)
|
||||
|
||||
self.table.resizeColumnsToContents()
|
||||
|
||||
self.searchbox.textChanged.connect(self.filter_table)
|
||||
|
||||
|
||||
|
||||
layout = QtWidgets.QGridLayout(self)
|
||||
layout.addWidget(self.searchbox, 0, 0)
|
||||
layout.addWidget(self.table, 1, 0)
|
||||
|
||||
layout.setRowStretch(0, 0)
|
||||
layout.setRowStretch(1, 1)
|
||||
|
||||
def filter_table(self):
|
||||
|
||||
searchquery = self.searchbox.text()
|
||||
|
||||
options = fuzzyfinder.main.fuzzyfinder(searchquery, self.opts, accessor=lambda x: x["name"])
|
||||
|
||||
for row_index, row_data in enumerate(options):
|
||||
for col_index, key in enumerate(row_data.keys()):
|
||||
value = row_data.get(key, "")
|
||||
self.table.setItem(
|
||||
row_index,
|
||||
col_index,
|
||||
QtWidgets.QTableWidgetItem(value)
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import core.data.scrapers.steamrip as sr
|
||||
|
||||
app = QtWidgets.QApplication([])
|
||||
widget = FuzzySearchWindow(sr.offline_scrape_steamrip_links())
|
||||
widget.resize(600,400)
|
||||
widget.show()
|
||||
|
||||
|
||||
exit(app.exec())
|
||||
Reference in New Issue
Block a user