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