-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlook.py
29 lines (25 loc) · 1.05 KB
/
look.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
import json
from bs4 import BeautifulSoup
def nintendoTitleLookup(titleid,region="US"):
url = f"https://ec.nintendo.com/apps/{titleid}/{region}"
try:
response = requests.get(url, allow_redirects=True)
response.raise_for_status()
soup = BeautifulSoup(response.content, "html.parser")
next_data = soup.find('script',id='__NEXT_DATA__')
if next_data:
tJson = json.loads(next_data.string)
tData = tJson['props']['pageProps']['initialApolloState']
required_subkeys = ['name', 'metaTitle', 'metaDescription', 'descriptionImage', 'softwarePublisher']
for key, value in tData.items():
if key.startswith('StoreProduct'):
if isinstance(value, dict):
if all(subkey in value for subkey in required_subkeys):
return value
else:
return False
except Exception as e:
print(f"Error: {e}")
return False
print(nintendoTitleLookup('010073C01AF34000'))