Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/belyi/old/db.py
1128 views
1
import pymongo
2
import os
3
_C = None
4
5
# server = "belyi.lmfdb.xyz:27017"
6
server = "localhost:37010" # run warwick.sh first
7
8
9
def makeDBconnection():
10
global _C
11
_C = pymongo.MongoClient(server)
12
_C.admin.authenticate("lmfdb", "lmfdb")
13
14
15
def getDBconnection():
16
if _C is None:
17
makeDBconnection()
18
return _C
19
20
21
_Cwrite = None
22
23
24
def makeDBconnection_write():
25
global _Cwrite
26
_Cwrite = pymongo.MongoClient(server)
27
# _Cwrite.admin.authenticate("lmfdb","lmfdb")
28
path = os.path.join(os.getcwd(), "../../passwords.yaml")
29
import yaml
30
pw_dict = yaml.load(path)
31
try:
32
pw_dict = yaml.load(open(path))
33
username = pw_dict['name']
34
password = pw_dict['password']
35
db = pw_dict['db']
36
_Cwrite[db].authenticate(username, password)
37
print("Logged in as %s in %s!1!1!" % (username, db,))
38
except Exception:
39
print("Failed to login")
40
41
42
def getDBconnection_write():
43
if _Cwrite is None:
44
makeDBconnection_write()
45
return _Cwrite
46
47