Path: blob/main/scripts/hecke_algebras/hecke_algebras.py
1128 views
# -*- coding: utf-8 -*-1r""" Import Hecke algebras.23Note: This code can be run on all files in any order. Even if you4rerun this code on previously entered files, it should have no affect.5This code checks if the entry exists, if so returns that and updates6with new information. If the entry does not exist then it creates it7and returns that.89"""1011import sys12import re13import json14import os15import gzip1617from lmfdb.base import getDBConnection1819C= getDBConnection()20import yaml21pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))22username = pw_dict['data']['username']23password = pw_dict['data']['password']24C['hecke_algebras'].authenticate('editor', password)25hecke_algebras = C['hecke_algebras'].hecke_algebras2627saving = True2829def sd(f):30for k in f.keys():31print('%s ---> %s'%(k, f[k]))3233def makels(li):34li2 = [str(x) for x in li]35return ','.join(li2)3637def string2list(s):38s = str(s)39if s=='': return []40return [int(a) for a in s.split(',')]41424344# The following create_index command checks if there is an index on45# label, dimension, determinant and level.464748hecke_algebras.create_index('level')49hecke_algebras.create_index('weight')50hecke_algebras.create_index('num_orbits')51hecke_algebras.create_index('label')5253print("finished indices")545556## Main importing function5758def do_import(ll):59level,weight,num_orbits,label = ll60mykeys = ['level','weight','num_orbits','label']61data = {}62for j in range(len(mykeys)):63data[mykeys[j]] = ll[j]6465alg = hecke_algebras.find_one({'label': label})6667if alg is None:68print("new hecke algebra")69alg = data70else:71print("hecke algebra already in the database")72alg.update(data)73if saving:74hecke_algebras.update({'label': label} , {"$set": alg}, upsert=True)75767778# Loop over files7980for path in sys.argv[1:]:81print(path)82filename = os.path.basename(path)83fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)84for line in fn.readlines():85line.strip()86if re.match(r'\S',line):87l = json.loads(line)88do_import(l)899091