Path: blob/main/scripts/groups/Make-images/load-imgs.py
1136 views
import sys, os, json1HOME=os.path.expanduser("~")2sys.path.append(os.path.join(HOME, 'lmfdb'))3from lmfdb import db45import base6467imdict = {}89# load the old images10for ent in db.gps_images.search():11imdict[ent['label']] = ent['image']1213print("Loaded old")1415# load the new ones, overwriting the old where applicable16with open("prettyindex", "r") as fn:17for line in fn.readlines():18l= json.loads(line)19fn2 = 'images/eq%d.png'% l[0]20imdict[l[1]] = 'data:image/png;base64,'+base64.b64encode(open(fn2, "rb").read()).decode("utf-8")2122print("Loaded new")23# Have all the image loaded2425afile = open("imagereloader", "w")26afile.write('label|image\n')27afile.write('text|text\n\n')282930for key,value in imdict.items():31afile.write(key.replace('\\','\\\\')+'|'+value.replace('\\','\\\\'))32afile.write('\n')33#inps.append({'label': key, 'image': value})34afile.close()35db.gps_images.reload('imagereloader')3637inps=[]38#for key,value in imdict.items():39# inps.append({'label': key, 'image': value})4041#db.gps_images.delete({})42#db.gps_images.insert_many(inps)434445