-
-
Save einstein95/6551cef749679e40b4f2a271c4fa127c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import json | |
import subprocess | |
import urllib | |
import urllib.request | |
import urllib.parse | |
API_HOST = "public-operation-hk4e-sg.hoyoverse.com" | |
def get_wish_urls(): | |
result = [] | |
cmd = "find ~/Library/Containers/com.miHoYo.GenshinImpact/Data/Library/Caches/WebKit -type f -exec strings {} \\; | grep e20190909gacha-v3 | grep -E '(https.+?game_biz=)' | uniq | more" | |
output = subprocess.check_output(cmd, shell=True) | |
for line in output.splitlines(): | |
result.append(line) | |
return result | |
def check_url(url) -> str: | |
uri = urllib.parse.urlparse(url) | |
path = "gacha_info/api/getGachaLog" | |
fragment = "" | |
query: dict = urllib.parse.parse_qs(uri.query) | |
query["lang"] = "en" | |
query["gacha_type"] = "301" | |
query["size"] = "5" | |
query["lang"] = "en-us" | |
q = urllib.parse.urlencode(query, doseq=True) | |
url = f'{uri.scheme.decode("utf-8")}://{API_HOST}/{path}?{q}#{fragment}' | |
try: | |
with urllib.request.urlopen(url, timeout=10) as request: | |
# parse json | |
data = json.loads(request.read()) | |
# check error code | |
if data["retcode"] == 0: | |
return url | |
except Exception as e: | |
print(e) | |
return "" | |
def main(): | |
urls = get_wish_urls() | |
found = False | |
for url in urls: | |
if api_url := check_url(url): | |
print(f"Found valid url: {api_url}") | |
# copy to clipboard, properly escaping the url | |
cmd = f'echo "{api_url}" | pbcopy' | |
os.system(cmd) | |
print("Copied to clipboard.") | |
found = True | |
break | |
if not found: | |
print("No valid url found.") | |
print("Done.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment