Spaces:
Build error
Build error
File size: 1,030 Bytes
81e77f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
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 |