-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
28 lines (23 loc) · 898 Bytes
/
db.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
__author__ = 'cook'
import mysql.connector
from mysql.connector import errorcode
## The database should have places for:
## tdate - datetime
## ttime - datetime
## sensor - which is a string
## zone - string
## celcius - Number
## fahrenheit - Number
class DB:
config = {'user': 'monitor', 'password': 'Pi314159', 'host': 'localhost', 'database': 'temps',
'raise_on_warnings': True}
def __init__(self):
try:
self.cnx = mysql.connector.connect(**self.config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password for the temperature database")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Temperature database does not exists")
else:
print(err)