From 4d25cde48f4b1cb10f8719c838375594eb4a5044 Mon Sep 17 00:00:00 2001 From: jorraan Date: Sat, 15 Jul 2023 10:51:07 +1000 Subject: [PATCH] Big ol commit --- .gitignore | 4 ++++ platforms.json | 33 +++++++++++++++++++++++++++++++++ platforms.py | 28 ++++++++++++++++++++++++++++ scraper/main.py | 16 ++++++++++++++++ scraper/scraper.py | 31 +++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 platforms.json create mode 100644 platforms.py create mode 100644 scraper/main.py create mode 100644 scraper/scraper.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c15731e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +py-env/ +venv/ +.vscode/ +*.ipynb \ No newline at end of file diff --git a/platforms.json b/platforms.json new file mode 100644 index 0000000..5e524a1 --- /dev/null +++ b/platforms.json @@ -0,0 +1,33 @@ +{ + "Sony":{ + "PS1": 22, + "PS2":19, + "PS3": 35, + "PS4": 146, + "PSVITA": 129 + }, + "Nintendo":{ + "Switch": 157, + "WII": 36, + "WIIU": 139, + "THREEDS": 117, + "GAMECUBE": 23, + "GBA": 4, + "GBC": 57, + "N64": 43, + "SNES": 9, + "GAMEBOY": 3, + "NES": 21 + }, + "Microsoft":{ + "XBOX": 32, + "XBOX_360": 20, + "XBOX_ONE": 145 + }, + "Misc":{ + "Mac": 17, + "PC": 94 + } + + +} \ No newline at end of file diff --git a/platforms.py b/platforms.py new file mode 100644 index 0000000..f2564fb --- /dev/null +++ b/platforms.py @@ -0,0 +1,28 @@ +# Platform ID's +# Sony +PS1 = 22 +PS2 = 19 +PS3 = 35 +PS4 = 146 +PSVITA = 129 + +# Nintendo +SWITCH = 157 +WII = 36 +WIIU = 139 +THREEDS = 117 +GAMECUBE = 23 +GBA = 4 +GBC = 57 +N64 = 43 +SNES = 9 +GAMEBOY = 3 +NES = 21 + +# Microsoft +XBOX = 32 +XBOX_360 = 20 +XBOX_ONE = 145 + +MAC = 17 +PC = 94 diff --git a/scraper/main.py b/scraper/main.py new file mode 100644 index 0000000..388e682 --- /dev/null +++ b/scraper/main.py @@ -0,0 +1,16 @@ +from pprint import pprint +from scraper import GameSearch + +my_key = "d1d6272bce2366c0a9441c418048dfcca820016a" + +game_search = GameSearch(my_key) + +response = game_search.quick_search('shin megami') + +name = game_search.get_name(response) + +overview = game_search.get_overview(response) + +image_url = game_search.get_icon_url(response) + +print(name, overview, image_url) \ No newline at end of file diff --git a/scraper/scraper.py b/scraper/scraper.py new file mode 100644 index 0000000..cffa34a --- /dev/null +++ b/scraper/scraper.py @@ -0,0 +1,31 @@ +import pybomb +from bs4 import BeautifulSoup + +class GameSearch: + def __init__(self, api_key): + self.games_client = pybomb.GamesClient(api_key) + + def quick_search(self, name, platform=None): + response = self.games_client.quick_search( + name=name.strip(), + platform=platform, + sort_by='original_release_date', + desc=True + ) + return response + + def get_name(self, response): + return response.results[0]['name'] + + def get_overview(self, response): + description_html = response.results[0]['description'] + soup = BeautifulSoup(description_html, 'html.parser') + overview_heading = soup.find('h2', string='Overview') + overview_text = overview_heading.find_next_sibling().get_text() + return overview_text + + def get_icon_url(self, response): + return response.results[0]['image']['icon_url'] + + def get_deck(self, response): + return response.results[0]['deck']