Big ol commit

This commit is contained in:
jorraan 2023-07-15 10:51:07 +10:00
parent 3997fd814d
commit 4d25cde48f
5 changed files with 112 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
py-env/
venv/
.vscode/
*.ipynb

33
platforms.json Normal file
View File

@ -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
}
}

28
platforms.py Normal file
View File

@ -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

16
scraper/main.py Normal file
View File

@ -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)

31
scraper/scraper.py Normal file
View File

@ -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']