Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/groups/Make-images/load-imgs.py
1136 views
1
import sys, os, json
2
HOME=os.path.expanduser("~")
3
sys.path.append(os.path.join(HOME, 'lmfdb'))
4
from lmfdb import db
5
6
import base64
7
8
imdict = {}
9
10
# load the old images
11
for ent in db.gps_images.search():
12
imdict[ent['label']] = ent['image']
13
14
print("Loaded old")
15
16
# load the new ones, overwriting the old where applicable
17
with open("prettyindex", "r") as fn:
18
for line in fn.readlines():
19
l= json.loads(line)
20
fn2 = 'images/eq%d.png'% l[0]
21
imdict[l[1]] = 'data:image/png;base64,'+base64.b64encode(open(fn2, "rb").read()).decode("utf-8")
22
23
print("Loaded new")
24
# Have all the image loaded
25
26
afile = open("imagereloader", "w")
27
afile.write('label|image\n')
28
afile.write('text|text\n\n')
29
30
31
for key,value in imdict.items():
32
afile.write(key.replace('\\','\\\\')+'|'+value.replace('\\','\\\\'))
33
afile.write('\n')
34
#inps.append({'label': key, 'image': value})
35
afile.close()
36
db.gps_images.reload('imagereloader')
37
38
inps=[]
39
#for key,value in imdict.items():
40
# inps.append({'label': key, 'image': value})
41
42
#db.gps_images.delete({})
43
#db.gps_images.insert_many(inps)
44
45