-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import json | ||
|
||
|
||
def save_to_disk(data, fname, verbose=False): | ||
with open(fname, "w", encoding="utf8") as f: | ||
json.dump(data, f) | ||
|
||
if verbose: | ||
print(f"#entries = {len(data)}") | ||
|
||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import requests | ||
|
||
from src.query_utils import get_query | ||
|
||
|
||
def get_geforce_url(): | ||
return "https://games.geforce.com/graphql" | ||
|
||
|
||
def fetch_page(cursor="", is_slim_query=True): | ||
print(f"Cursor: {cursor}") | ||
|
||
r = requests.post( | ||
url=get_geforce_url(), | ||
json={"query": get_query(cursor, is_slim_query=is_slim_query)}, | ||
) | ||
if r.ok: | ||
data = r.json() | ||
item_info = data["data"]["apps"]["items"] | ||
page_info = data["data"]["apps"]["pageInfo"] | ||
else: | ||
item_info = None | ||
page_info = None | ||
|
||
return item_info, page_info | ||
|
||
|
||
def fetch_all_pages(is_slim_query=True): | ||
data = [] | ||
|
||
has_next_page = True | ||
cursor = "" | ||
|
||
while has_next_page: | ||
item_info, page_info = fetch_page(cursor, is_slim_query=is_slim_query) | ||
|
||
data += item_info | ||
|
||
has_next_page = page_info["hasNextPage"] | ||
cursor = page_info["endCursor"] | ||
|
||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
def get_query(cursor, is_slim_query=True): | ||
query_prefixe = "{" | ||
|
||
query_header = f'apps(first: 1200, after: "{cursor}")' | ||
|
||
qery_metadata = """{ | ||
numberReturned | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
totalCount | ||
}""" | ||
|
||
query_content = get_query_content(is_slim_query=is_slim_query) | ||
|
||
query_suffixe = "} }" | ||
|
||
return query_prefixe + query_header + qery_metadata + query_content + query_suffixe | ||
|
||
|
||
def get_query_content(is_slim_query=True): | ||
if is_slim_query: | ||
query_content = get_slim_query_content() | ||
else: | ||
query_content = get_full_query_content() | ||
|
||
return query_content | ||
|
||
|
||
def get_slim_query_content(): | ||
query_content = """ | ||
items { | ||
id | ||
title | ||
developerName | ||
publisherName | ||
type | ||
osType | ||
storeIds { | ||
store | ||
id | ||
} | ||
computedValues { | ||
earliestReleaseDate | ||
earliestStreetDate | ||
} | ||
} | ||
""" | ||
|
||
return query_content | ||
|
||
|
||
def get_full_query_content(): | ||
query_content = """ | ||
items { | ||
osType | ||
id | ||
cmsId | ||
sortName | ||
title | ||
longDescription | ||
contentRatings { | ||
type | ||
categoryKey | ||
} | ||
developerName | ||
geForceUrl | ||
images { | ||
FEATURE_IMAGE | ||
GAME_BOX_ART | ||
HERO_IMAGE | ||
KEY_ART | ||
KEY_ICON | ||
KEY_IMAGE | ||
TV_BANNER | ||
SCREENSHOTS | ||
} | ||
keywords | ||
maxLocalPlayers | ||
maxOnlinePlayers | ||
apks { | ||
type | ||
version | ||
url | ||
} | ||
publisherName | ||
storeIds { | ||
id | ||
store | ||
} | ||
streamingModes { | ||
framesPerSecond | ||
heightInPixels | ||
widthInPixels | ||
} | ||
supportedControls | ||
supportedGamePlayModes | ||
type | ||
computedValues { | ||
earliestReleaseDate | ||
earliestStreetDate | ||
allKeywords | ||
} | ||
genres | ||
appStore | ||
variants { | ||
id | ||
title | ||
appStore | ||
developerName | ||
gfn { | ||
status | ||
visibility | ||
releaseDate | ||
isInLibrary | ||
} | ||
osType | ||
storeId | ||
} | ||
} | ||
""" | ||
|
||
return query_content |