API to get gift codes from Hoyoverse games, made for auto code redemption feature in hoyo buddy.
- Genshin: https://hoyo-codes.seriaati.xyz/codes?game=genshin
- Honkai Star Rail: https://hoyo-codes.seriaati.xyz/codes?game=hkrpg
- Honkai Impact 3rd: https://hoyo-codes.seriaati.xyz/codes?game=honkai3rd
- The
run.py
file is responsible for running the API - The
update.py
file is used to fetch codes from the sources listed in/api/codes/sources.py
- The
check.py
file is used to check the status of old codes to see if they have expired
- We first use
aiohttp
to get the website's HTML. For pockettactics you would need a user agent, else the website blocks you, this is why thefake-useragent
package is used - Then we parse the HTML using
beautifulsoup
+lxml
(for faster parsing), then extract the codes from the website by inspecting the HTML elements - Next we verify the status of the each code with
genshin.py
, we would request to HoYoLAB to redeem a specific code, and save the code with differentCodeStatus
(OK or NOT_OK) based on the redemption result. If the code already exists in the database, we would skip the verification process
- We get all the codes in the database with
CodeStatus.OK
and verify their status with the same technique used inupdate.py
- Update the code with the new status
The API grabs the codes from the database with CodeStatus.OK
and game with the game requested
The API runs on my machine, and I schedule 2 tasks:
update.py
to run once every 2 hourscheck.py
to run once everyday
Unfortunately, I don't play Honkai Impact 3rd, so I can't verify the status of HI3 codes.