Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Facenapalm committed Jun 6, 2024
1 parent 9f798d8 commit 5a1512a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
41 changes: 21 additions & 20 deletions seek_lutris_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from urllib.parse import unquote
from common.seek_basis import SearchIDSeekerBot

class LutrisSeekerBot(SearchIDSeekerBot):
class LutrisBot():
ids_data = {
"igdb": {
"property": "P5794",
Expand Down Expand Up @@ -64,25 +64,6 @@ class LutrisSeekerBot(SearchIDSeekerBot):
# TODO: GOG DB (for example: https://lutris.net/games/the-chaos-engine/ ) ?
}

def __init__(self):
super().__init__(
database_property="P7597",
default_matching_property="P1733",
allowed_matching_properties=[entry["property"] for entry in self.ids_data.values()],
)

def search(self, query, max_results=None):
params = {
"q": query,
"unpublished-filter": "on"
}
response = requests.get("https://lutris.net/games", params=params, headers=self.headers)
time.sleep(1)
if not response:
raise RuntimeError(f"can't get search results for query `{query}`. Status code: {response.status_code}")

return re.findall(r"<div class=[\"']game-preview[\"']>\s+<a href=[\"']/games/([^\"']+)/\"", response.text)

def parse_entry(self, entry_id):
response = requests.get(f"https://lutris.net/games/{entry_id}", headers=self.headers)
time.sleep(1)
Expand All @@ -105,5 +86,25 @@ def parse_entry(self, entry_id):
print(f"WARNING: {data['property']} found, but `{href}` doesn't match a mask")
return result

class LutrisSeekerBot(LutrisBot, SearchIDSeekerBot):
def __init__(self):
super().__init__(
database_property="P7597",
default_matching_property="P1733",
allowed_matching_properties=[entry["property"] for entry in self.ids_data.values()],
)

def search(self, query, max_results=None):
params = {
"q": query,
"unpublished-filter": "on"
}
response = requests.get("https://lutris.net/games", params=params, headers=self.headers)
time.sleep(1)
if not response:
raise RuntimeError(f"can't get search results for query `{query}`. Status code: {response.status_code}")

return re.findall(r"<div class=[\"']game-preview[\"']>\s+<a href=[\"']/games/([^\"']+)/\"", response.text)

if __name__ == "__main__":
LutrisSeekerBot().run()
7 changes: 3 additions & 4 deletions seek_lutris_id_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@
"""

from common.seek_basis import DirectIDSeekerBot
from seek_lutris_id import LutrisSeekerBot
from seek_lutris_id import LutrisBot

class LutrisSeekerBotLite(DirectIDSeekerBot):
class LutrisSeekerBotLite(LutrisBot, DirectIDSeekerBot):
def __init__(self):
super().__init__(
database_property='P7597',
default_matching_property='P5794',
)
self.seeker = LutrisSeekerBot()

def seek_database_entry(self):
parsed_entry = self.seeker.parse_entry(self.matching_value)
parsed_entry = self.parse_entry(self.matching_value)
if 'P5794' not in parsed_entry:
raise RuntimeError(f'Lutris entry `{self.matching_value}` have no backlink to IGDB')
if parsed_entry['P5794'] != self.matching_value:
Expand Down
2 changes: 1 addition & 1 deletion seek_playground_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self):
super().__init__(
database_property='P10354',
default_matching_property='P1733',
allowed_matching_properties=['P1733', 'P6278'],
allowed_matching_properties=[entry["property"] for entry in self.stores_data.values() if entry],
)

def search(self, query, max_results=None):
Expand Down

0 comments on commit 5a1512a

Please sign in to comment.