1
0
Fork 0
mirror of synced 2024-06-28 11:11:15 +12:00

Load browse_games.py when tab clicked

This commit is contained in:
Dummerle 2021-06-18 00:29:36 +02:00
parent 374e8193ac
commit 72457c8b27
3 changed files with 7 additions and 60 deletions

View file

@ -1,12 +1,12 @@
import os
from PyQt5.QtWidgets import QStackedWidget, QTabWidget
from custom_legendary.core import LegendaryCore
from custom_legendary.core import LegendaryCore
from rare.components.tabs.shop.browse_games import BrowseGames
from rare.components.tabs.shop.search_results import SearchResults
from rare.components.tabs.shop.shop_info import ShopGameInfo
from rare.components.tabs.shop.shop_widget import ShopWidget
from rare.components.tabs.shop.browse_games import BrowseGames
class Shop(QStackedWidget):
@ -28,6 +28,7 @@ class Shop(QStackedWidget):
self.store_tabs = QTabWidget()
self.store_tabs.addTab(self.shop, self.tr("Games"))
self.store_tabs.addTab(self.browse_games, self.tr("Browse"))
self.store_tabs.tabBarClicked.connect(lambda x: self.browse_games.load() if x == 1 else None)
self.addWidget(self.store_tabs)
@ -48,7 +49,7 @@ class Shop(QStackedWidget):
if not self.init:
self.init = True
self.shop.load()
self.browse_games.prepare_request()
# self.browse_games.prepare_request()
def show_game_info(self, data):
self.info.update_game(data)

View file

@ -64,6 +64,9 @@ class BrowseGames(QWidget, Ui_browse_games):
checkbox.deactivated.connect(lambda x: self.prepare_request(removed_type=x))
self.type_gb.layout().addWidget(checkbox)
def load(self):
self.prepare_request()
def prepare_request(self, price: str = None, added_tag: int = 0, removed_tag: int = 0,
added_type: str = "", removed_type: str = ""):

View file

@ -1,57 +0,0 @@
import requests
from PyQt5.QtCore import QThread, pyqtSignal
from custom_legendary.core import LegendaryCore
from rare.components.tabs.shop.browse_games import game_query
from rare.components.tabs.shop.shop_models import ShopGame
from rare.utils.utils import get_lang
class AnalyzeThread(QThread):
get_tags = pyqtSignal(dict)
def __init__(self, core: LegendaryCore):
super(AnalyzeThread, self).__init__()
self.tags = {}
self.core = core
def run(self) -> None:
locale = get_lang()
for igame in self.core.get_installed_list():
data = {
"query": game_query,
"variables": {"category": "games/edition/base|bundles/games|editors|software/edition/base",
"count": 20,
"country": locale.upper(), "keywords": igame.title, "locale": locale, "sortDir": "DESC",
"allowCountries": locale.upper(),
"start": 0, "tag": "", "withMapping": False, "withPrice": True}
}
try:
search_game = \
requests.post("https://www.epicgames.com/graphql", json=data).json()["data"]["Catalog"]["searchStore"][
"elements"][0]
except:
continue
slug = search_game["productSlug"]
is_bundle = False
for i in search_game["categories"]:
if "bundles" in i.get("path", ""):
is_bundle = True
api_game = requests.get(
f"https://store-content.ak.epicgames.com/api/{locale}/content/{'products' if not is_bundle else 'bundles'}/{slug}").json()
if api_game.get("error"):
print(igame.title)
continue
game = ShopGame.from_json(api_game, search_game)
for i in game.tags:
if i not in self.tags.keys():
self.tags[i] = 1
else:
self.tags[i] += 1
print(self.tags)