get_discord_emoji.py: decode python better
This commit is contained in:
parent
b2753bddf8
commit
2eea92f9e5
|
@ -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
|
||||||
except json.JSONDecodeError as jde:
|
jsondata = jsondata[end:]
|
||||||
obj = json.loads(jsondata[0 : jde.pos])
|
|
||||||
if obj.get("t", "") == "READY":
|
|
||||||
return obj
|
|
||||||
jsondata = jsondata[jde.pos :]
|
|
||||||
|
|
||||||
|
|
||||||
def main(*args):
|
def main(*args):
|
||||||
|
|
Loading…
Reference in a new issue