mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
now displaying the actual names of the game, not the links, links are in the 'link' key.
This commit is contained in:
@@ -17,18 +17,23 @@ def scrape_steamrip_links(text = None):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
links = []
|
links = []
|
||||||
for i, gamehtml in enumerate(games):
|
names = []
|
||||||
if i == 0: print(gamehtml)
|
for gamehtml in games:
|
||||||
link = gamehtml.find("a", href=lambda x: x and x.startswith("/"))
|
link = gamehtml.find("a", href=lambda x: x and x.startswith("/"))
|
||||||
links += re.findall('(?<=href=")[^"]*', link.__str__())
|
links += re.findall('(?<=href=")[^"]*', link.__str__())
|
||||||
|
name = gamehtml.find("a", href=lambda x: x and x.startswith("/"))
|
||||||
|
names += re.findall('(?<=\/">)[^<]*', name.__str__())
|
||||||
|
|
||||||
|
print(names)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# construct the list[dict[str,str]]
|
# construct the list[dict[str,str]]
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
for link in links:
|
for i in range(len(names)-1):
|
||||||
ret.append({"name" : link})
|
ret.append({"name" : names[i], "link" : links[i]})
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import fuzzyfinder
|
|||||||
from PySide6 import QtCore, QtWidgets, QtGui
|
from PySide6 import QtCore, QtWidgets, QtGui
|
||||||
from sys import exit
|
from sys import exit
|
||||||
|
|
||||||
class FuzzySearchWindow(QtWidgets.QWidget):
|
class FuzzySearchWindow(QtWidgets.QWidget): # should work everywhere
|
||||||
"""
|
"""
|
||||||
The dict should contain a:
|
The dict should contain a:
|
||||||
name : str
|
name : str
|
||||||
@@ -15,17 +15,26 @@ class FuzzySearchWindow(QtWidgets.QWidget):
|
|||||||
|
|
||||||
The key will be at the Top of the Table
|
The key will be at the Top of the Table
|
||||||
The value will be listed for each element
|
The value will be listed for each element
|
||||||
|
|
||||||
|
keys in ignorekeys will be ignored and not displayed, e.g. if oyu have links in the database which arent relevant
|
||||||
"""
|
"""
|
||||||
def __init__(self, options: list[dict[str, str]]):
|
def __init__(self, options: list[dict[str, str]], ignorekeys: list[str] = []):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.opts: list[dict[str, str]] = options
|
self.opts: list[dict[str, str]] = options
|
||||||
|
self.ignorekeys = ignorekeys
|
||||||
|
|
||||||
self.searchbox = QtWidgets.QLineEdit()
|
self.searchbox = QtWidgets.QLineEdit()
|
||||||
self.searchbox.placeholderText = "Search for a game"
|
self.searchbox.placeholderText = "Search for a game"
|
||||||
|
|
||||||
self.table = QtWidgets.QTableWidget()
|
self.table = QtWidgets.QTableWidget()
|
||||||
headers = self.opts[1].keys()
|
|
||||||
|
headers = []
|
||||||
|
for key in self.opts[1].keys():
|
||||||
|
if key not in self.ignorekeys:
|
||||||
|
headers.append(key)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(headers)
|
print(headers)
|
||||||
self.table.setColumnCount(len(headers))
|
self.table.setColumnCount(len(headers))
|
||||||
@@ -34,7 +43,9 @@ class FuzzySearchWindow(QtWidgets.QWidget):
|
|||||||
self.table.setRowCount(len(self.opts))
|
self.table.setRowCount(len(self.opts))
|
||||||
for row_index, row_data in enumerate(self.opts):
|
for row_index, row_data in enumerate(self.opts):
|
||||||
for col_index, key in enumerate(headers):
|
for col_index, key in enumerate(headers):
|
||||||
value = row_data.get(key, "")[1:-1].replace("-", " ")
|
if key in self.ignorekeys:
|
||||||
|
continue
|
||||||
|
value = row_data.get(key, "")
|
||||||
item = QtWidgets.QTableWidgetItem(value)
|
item = QtWidgets.QTableWidgetItem(value)
|
||||||
self.table.setItem(row_index, col_index, item)
|
self.table.setItem(row_index, col_index, item)
|
||||||
|
|
||||||
@@ -59,6 +70,8 @@ class FuzzySearchWindow(QtWidgets.QWidget):
|
|||||||
|
|
||||||
for row_index, row_data in enumerate(options):
|
for row_index, row_data in enumerate(options):
|
||||||
for col_index, key in enumerate(row_data.keys()):
|
for col_index, key in enumerate(row_data.keys()):
|
||||||
|
if key in self.ignorekeys:
|
||||||
|
continue
|
||||||
value = row_data.get(key, "")
|
value = row_data.get(key, "")
|
||||||
self.table.setItem(
|
self.table.setItem(
|
||||||
row_index,
|
row_index,
|
||||||
@@ -71,7 +84,7 @@ if __name__ == "__main__":
|
|||||||
import core.data.scrapers.steamrip as sr
|
import core.data.scrapers.steamrip as sr
|
||||||
|
|
||||||
app = QtWidgets.QApplication([])
|
app = QtWidgets.QApplication([])
|
||||||
widget = FuzzySearchWindow(sr.offline_scrape_steamrip_links())
|
widget = FuzzySearchWindow(sr.offline_scrape_steamrip_links(), ["link"])
|
||||||
widget.resize(600,400)
|
widget.resize(600,400)
|
||||||
widget.show()
|
widget.show()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user