Skip to content

Commit

Permalink
fix: fake user agent to avoid being rate limitted by api
Browse files Browse the repository at this point in the history
  • Loading branch information
kurokobo committed May 12, 2023
1 parent ff20ac3 commit 8e974fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 16 additions & 3 deletions helper/app_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ def gather_epicgames():

def gather_gog_id(id):
# get name
_response = requests.get("https://api.gog.com/products/" + str(id))
_ua = (
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) "
"Chrome/22.0.1216.0 Safari/537.2"
)
_headers = {"User-Agent": _ua}
_response = requests.get(
"https://api.gog.com/products/" + str(id), headers=_headers
)
_response.close()
_name = _response.json()["title"]

# get branch info
_response = requests.get(
"https://content-system.gog.com/products/"
+ str(id)
+ "/os/windows/builds?generation=2"
+ "/os/windows/builds?generation=2",
headers=_headers,
)
_response.close()
_product_info = _response.json()
Expand All @@ -127,8 +135,13 @@ def gather_gog_id(id):

def gather_gog_name(name):
_endpoint = "https://embed.gog.com/games/ajax/filtered"
_ua = (
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) "
"Chrome/22.0.1216.0 Safari/537.2"
)
_headers = {"User-Agent": _ua}
_params = {"search": name}
_response = requests.get(url=_endpoint, params=_params)
_response = requests.get(url=_endpoint, headers=_headers, params=_params)
_response.close()
_search_matches = _response.json()

Expand Down
11 changes: 9 additions & 2 deletions modules/gog.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def gather_app_info(self):
"Request product information for apps: {}".format([a.id for a in self.apps])
)
_product_info = {}
_ua = (
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) "
"Chrome/22.0.1216.0 Safari/537.2"
)
_headers = {"User-Agent": _ua}

for a in self.apps:
if a.id not in _product_info:
try:
# get game name
_response = requests.get(
"https://api.gog.com/products/" + str(a.id)
"https://api.gog.com/products/" + str(a.id), headers=_headers
)
if _response.status_code != 200:
self.logger.error(
Expand All @@ -104,7 +110,8 @@ def gather_app_info(self):
_response = requests.get(
"https://content-system.gog.com/products/"
+ str(a.id)
+ "/os/windows/builds?generation=2"
+ "/os/windows/builds?generation=2",
headers=_headers,
)
if _response.status_code != 200:
self.logger.error(
Expand Down

0 comments on commit 8e974fd

Please sign in to comment.