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): def get_data(filename):
bindata = open(filename, "rb").read() bindata = open(filename, "rb").read()
decompress = zlib.decompressobj() decompress = zlib.decompressobj()
jsondata = decompress.decompress(bindata) jsondata = decompress.decompress(bindata).decode("utf-8")
decoder = json.JSONDecoder()
while len(jsondata) > 0: while len(jsondata) > 0:
try: obj, end = decoder.raw_decode(jsondata)
obj = json.loads(jsondata) if obj.get("t", "") == "READY":
if obj.get("t", "") == "READY": return obj
return obj jsondata = jsondata[end:]
except json.JSONDecodeError as jde:
obj = json.loads(jsondata[0 : jde.pos])
if obj.get("t", "") == "READY":
return obj
jsondata = jsondata[jde.pos :]
def main(*args): def main(*args):