-
-
Save spaceface777/8c169ee8eac2b246433c2e8d00767940 to your computer and use it in GitHub Desktop.
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
import os | |
import subprocess | |
import json | |
import urllib | |
import urllib.request | |
import urllib.parse | |
API_HOST = "hk4e-api-os.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 | egrep '(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) -> bool: | |
uri = urllib.parse.urlparse(url) | |
path = "event/gacha_info/api/getGachaLog" | |
host = API_HOST | |
fragment = "" | |
query = urllib.parse.parse_qs(uri.query) | |
query["lang"] = "en" | |
query["gacha_type"] = "301" | |
query["size"] = "5" | |
query["lang"] = "en-us" | |
query = urllib.parse.urlencode(query, doseq=True) | |
url = uri.scheme.decode("utf-8") + "://" + API_HOST + "/" + path + "?" + query + "#" + fragment | |
# print(url) | |
try: | |
response = urllib.request.urlopen(url, timeout=10) | |
# parse json | |
data = json.loads(response.read()) | |
# check error code | |
if data["retcode"] == 0: | |
return True | |
return False | |
except Exception as e: | |
# print(e) | |
return False | |
def main(): | |
urls = get_wish_urls() | |
found = False | |
for url in urls: | |
if check_url(url): | |
print("Found valid url: " + url.decode('utf-8')) | |
# copy to clipboard, properly escaping the url | |
cmd = f'echo "{url.decode("utf-8")}" | pbcopy' | |
os.system(cmd) | |
print("Copied to clipboard.") | |
found = True | |
break | |
print("No valid url found.") if not found else None | |
print("Done.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment