-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathridatabase.py
37 lines (29 loc) · 948 Bytes
/
ridatabase.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
#
# Author: jun10000 (https://github.com/jun10000)
#
from datetime import datetime
import pymysql
import settings
class RIDatabase:
__con = None
def connect(self):
self.__con = pymysql.Connect(
host=settings.common['Database']['Host'],
user=settings.common['Database']['User'],
password=settings.common['Database']['Password'],
cursorclass=pymysql.cursors.DictCursor)
def disconnect(self):
if self.__con is not None:
self.__con.close()
def insert_signal(self, name):
with self.__con.cursor() as cursor:
cursor.execute(
'INSERT INTO onkyori.signals(clock, name) VALUES (%s, %s)',
(datetime.now(), name))
self.__con.commit()
def __enter__(self):
self.connect()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.disconnect()
return True