Skip to content

Commit 9fbd405

Browse files
authored
Migrate to cloudscraper for requests & change the graphql url (#31)
* Change the GraphQL url's subdomain from graphql to store; * Set the GraphQL url as an attribute; * Replace requests with cloudscraper.
1 parent 95a7b1e commit 9fbd405

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

epicstore_api/api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525
from typing import NamedTuple
2626

27-
import requests
27+
import cloudscraper
2828

2929
from epicstore_api.exc import EGSException, EGSNotFound
3030
from epicstore_api.models import EGSCategory, EGSCollectionType, EGSProductType
@@ -72,7 +72,8 @@ def __init__(self, locale="en-US", country="US", session=None) -> None:
7272
""":param locale: EGS locale (this parameter depends on responses locale)
7373
:param country: EGS country
7474
"""
75-
self._session = requests.Session() or session
75+
self._session = session or cloudscraper.create_scraper()
76+
self._graphql_url = "https://store.epicgames.com/graphql"
7677
self.locale = locale
7778
self.country = country
7879

@@ -437,7 +438,7 @@ def _make_graphql_query(
437438
variables.update({'locale': self.locale, 'country': self.country})
438439
# This variables are default and exist in all graphql queries
439440
response = self._session.post(
440-
'https://graphql.epicgames.com/graphql',
441+
self._graphql_url,
441442
json={'query': query_string, 'variables': variables},
442443
headers=headers,
443444
).json()
@@ -451,7 +452,7 @@ def _make_graphql_query(
451452
variables_.update(variables)
452453
data.append({'query': query_string, 'variables': variables_})
453454
response = self._session.post(
454-
'https://graphql.epicgames.com/graphql',
455+
self._graphql_url,
455456
json=data,
456457
headers=headers,
457458
).json()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
requests
1+
cloudscraper

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
url='https://github.com/SD4RK/epicstore_api',
1818
license='MIT',
1919
include_package_data=True,
20-
install_requires=['requests>=2.28.1'],
20+
install_requires=['cloudscraper>=1.2.71'],
2121
download_url=f'https://github.com/SD4RK/epicstore_api/archive/v_{VERSION}.tar.gz',
2222
packages=setuptools.find_packages(),
2323
classifiers=[

0 commit comments

Comments
 (0)