-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbinterface.py
48 lines (44 loc) · 1.21 KB
/
dbinterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pymysql.cursors
import requests
from requests.exceptions import HTTPError
def initdb(CID):
DC=getdb(CID)
if (DC>4):
host=(DC*2)+2
else:
host=(DC*2)-1
#Fix to make sure we always get two digits hosts
# IE dbp3 is actually dbp03
if (host < 10) :
hoststr='0'+str(host)
else :
hoststr=str(host)
connection = pymysql.connect(host='dbp'+hoststr,
user='TEST',
passwd='TEST',
db='TEST',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
return connection
def initdb_staging(CID):
DC=getdb(CID)
if (DC>4):
host=(DC*2)+2
else:
host=DC*2
print host
#Fix to make sure we always get two digits hosts
# IE dbp3 is actually dbp03
if (host < 10) :
hoststr='0'+str(host)
else :
hoststr=str(host)
print hoststr
connection = pymysql.connect(host='dbp'+hoststr,
user='TEST',
passwd='TEST',
db='TEST',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
return connection
#print connection.messages