get_discord_emoji.py: decode python better

This commit is contained in:
Artemis Tosini 2024-03-25 22:24:56 +00:00
parent b2753bddf8
commit 2eea92f9e5
Signed by: artemist
GPG key ID: EE5227935FE3FF18

View file

@ -27,17 +27,13 @@ def download_file(url, path):
def get_data(filename):
bindata = open(filename, "rb").read()
decompress = zlib.decompressobj()
jsondata = decompress.decompress(bindata)
jsondata = decompress.decompress(bindata).decode("utf-8")
decoder = json.JSONDecoder()
while len(jsondata) > 0:
try:
obj = json.loads(jsondata)
if obj.get("t", "") == "READY":
return obj
except json.JSONDecodeError as jde:
obj = json.loads(jsondata[0 : jde.pos])
if obj.get("t", "") == "READY":
return obj
jsondata = jsondata[jde.pos :]
obj, end = decoder.raw_decode(jsondata)
if obj.get("t", "") == "READY":
return obj
jsondata = jsondata[end:]
def main(*args):