A wrapper for the official hoyolab.com Genshin impact gameRecord API.
Project description
genshinstats
This project is meant to be a wrapper for the hoyolab.com gameRecord api. I have attempted to reverse engineer their API to find out the important tokens and cookies and then to what urls they are sent. You can pip install with PyPI
how to use
Import the genshinstats
module and do set_cookie(...)
to login.
You can either use set_cookie(account_id=..., cookie_token=...)
.
The cookie is required and will raise an error if missing.
All functions are documented and type hinted.
examples
Simple examples of usage:
import genshinstats as gs # import module
gs.set_cookie(account_id=119480035, cookie_token="hEIIh08ghAIlHY1QQZBnsngVWXzaEMQtrSV0Bowu") # login
uid = 710785423
user_info = gs.get_user_info(uid) # get user info with a uid
total_characters = len(user_info['characters']) # get the amount of characters
print('user "sadru" has a total of',total_characters,'characters')
Cookies should be your own. These are just some example cookies of an account that can be deleted at any time.
stats = gs.get_user_info(uid)['stats']
for field,value in stats.items():
print(f'{field.replace("_"," ")}: {value}')
characters = gs.get_all_characters(uid)
for char in characters:
print(f"{char['rarity']}* {char['name']:10} Level: {char['level']:2} C{char['constellation']}")
spiral_abyss = gs.get_spiral_abyss(uid,previous=True)
stats = spiral_abyss['stats']
for field,value in stats.items():
print(f'{field.replace("_"," ")}: {value}')
gacha log
You can also get your gacha pull logs. For this you must first open the history page in genshin impact. The script will then get all required data by itself.
types = gs.get_gacha_types() # get the types
name = types[2]['name'] # name == "Character Event Wish"
log = gs.get_gacha_log(name) # get the gacha log
for i in log:
print(f"{i['time']} - {i['name']} ({i['rarity']}* {i['type']})")
View other's history by setting a authkey yourself.
gs.set_authkey("D3ZYe49SUzpDgzrt/l00n2673Zg8N/Yd9OSc7NulRHhp8EhzlEnz2ISBtKBR0fZ/DGs8...")
gs.set_authkey(logfile='other_output_log.txt')
Since the authkey lasts only a day this is more like for exporting than for actual use.
how to get your cookie
- go to hoyolab.com
- login to your account
- open inspect mode (Developer Tools)
- go to
Application
,Cookies
,https://www.hoyolab.com
. - copy
account_id
andcookie_token
- use
set_cookie(account_id=..., cookie_token=...)
in your code
about this project
contribution
All contributions are welcome as long as it's in a form of a clean PR. Currently looking for people to reverse engineer the new api version.
crediting
This project can be freely downloaded and distributed. Crediting is appreciated.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file genshinstats-1.2.1.tar.gz
.
File metadata
- Download URL: genshinstats-1.2.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ada3e022a52f7c64f5c8c8779d46a5f589224634e655cd1a93b0d63360ff8af1 |
|
MD5 | c7455a3ccb0d754798b6b09f574e996a |
|
BLAKE2b-256 | 914eb64cc6fd3c7e4048ba1161a5261521961c7534614f34642df50570a685c5 |