Spaces:
Build error
Build error
import json | |
import hashlib | |
import random | |
import string | |
def get_unique_name(): | |
return ''.join([random.choice(string.ascii_letters | |
+ string.digits) for n in range(32)]) | |
def read_json_lines(file): | |
with open(file,'r',encoding="utf8") as f: | |
lines = f.readlines() | |
data=[] | |
for l in lines: | |
data.append(json.loads(l)) | |
return data | |
def json_dump(thing): | |
return json.dumps(thing, | |
ensure_ascii=False, | |
sort_keys=True, | |
indent=None, | |
separators=(',', ':')) | |
def get_hash(thing): # stable-hashing | |
return str(hashlib.md5(json_dump(thing).encode('utf-8')).hexdigest()) | |
def dump_json(thing,file): | |
with open(file,'w+',encoding="utf8") as f: | |
json.dump(thing,f) | |
def read_json_lines(file): | |
with open(file,'r',encoding="utf8") as f: | |
lines = f.readlines() | |
data=[] | |
for l in lines: | |
data.append(json.loads(l)) | |
return data |