Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/number_fields/import_nf_data.py
1128 views
1
#!/usr/local/bin/sage -python
2
# -*- coding: utf-8 -*-
3
r""" Import number field data.
4
5
Imports from a json file directly to the database.
6
7
Data is imported to the collection 'nf_fields'.
8
"""
9
10
import sys
11
import re
12
import json
13
14
sys.path.append('/scratch/home/jj/lmfdb')
15
16
from lmfdb import db
17
18
fields = db.nf_fields
19
20
outrecs = []
21
tot = 0
22
for path in sys.argv[1:]:
23
print (path)
24
fn = open(path)
25
for line in fn.readlines():
26
line.strip()
27
if re.match(r'\S',line):
28
l = json.loads(line)
29
outrecs.append(l)
30
tot += 1
31
32
if len(outrecs)>0:
33
fields.insert_many(outrecs)
34
35
print ("Added %d records"% tot)
36
37
38
39