From cf1bab632c9462e78eab3eb3a3085d845108fd2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Wed, 17 Apr 2019 21:45:52 +0900 Subject: [PATCH] Add: unpaid_maestro_checker.py --- src/web/python/batch/db_manager.py | 46 +++++++++++-------- src/web/python/batch/db_setting.py | 14 ++++-- src/web/python/batch/test_python.py | 21 +++++---- .../python/batch/unpaid_maestro_checker.py | 23 ++++++++++ 4 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 src/web/python/batch/unpaid_maestro_checker.py diff --git a/src/web/python/batch/db_manager.py b/src/web/python/batch/db_manager.py index bdf6f43..c2cc7c3 100644 --- a/src/web/python/batch/db_manager.py +++ b/src/web/python/batch/db_manager.py @@ -11,31 +11,18 @@ class DBConnectParams: self.db = 'chocomae' self.charset = 'utf8' - def setHost(self, value): - self.host = value - - def setPort(self, value): - self.port = value - - def setUser(self, value): - self.user = value - - def setPassword(self, value): - self.password = value - - def setDB(self, value): - self.db = value - - def setCharset(self, value): - self.charset = value - class DBManager: def __init__(self): + print('init') self.conn = None self.curs = None super().__init__() + def close(self): + print('close') + self.conn.close() + def connect(self, dbParam): self.conn = pymysql.connect( host=dbParam.host, port=dbParam.port, @@ -43,6 +30,27 @@ class DBManager: db=dbParam.db, charset=dbParam.charset) self.curs = self.conn.cursor(pymysql.cursors.DictCursor) + def select(self, sql): + self.curs.execute(sql) + rows = self.curs.fetchall() + return rows + + def insert(self, sql, params): + self.executeSql(sql, params) + + + def update(self, sql, params): + self.executeSql(sql, params) + + + def delete(self, sql, params): + self.executeSql(sql, params) + + def executeSql(self, sql, params): + self.curs.execute(sql, params) + self.conn.commit() + + def getWaitingAccountList(self): sql = "select * from maestro" self.curs.execute(sql) @@ -63,4 +71,4 @@ class DBManager: unregisteredAccountCount += 1 # print(unregisteredAccountCount) - self.conn.close() \ No newline at end of file + # self.conn.close() \ No newline at end of file diff --git a/src/web/python/batch/db_setting.py b/src/web/python/batch/db_setting.py index 1eeed7b..14256f6 100644 --- a/src/web/python/batch/db_setting.py +++ b/src/web/python/batch/db_setting.py @@ -1,9 +1,13 @@ class DBSetting: host = 'localhost' - # port = 3306 # service, test server - port = 8889 # mac user = 'jisangs' - # password = '52napark!' # service, test server - password = 'Fr12nds95' # mac db = 'chocomae' - charset = 'utf8' \ No newline at end of file + charset = 'utf8' + + # service, test server + # port = 3306 + # password = '52napark!' + + # mac + port = 8889 + password = 'Fr12nds95' diff --git a/src/web/python/batch/test_python.py b/src/web/python/batch/test_python.py index 1b4d85a..0e19325 100644 --- a/src/web/python/batch/test_python.py +++ b/src/web/python/batch/test_python.py @@ -1,11 +1,12 @@ -from db_setting import DBSetting -from db_manager import DBConnectParams, DBManager +from unpaid_maestro_checker import UnpaidMaestroChecker -dbParams = DBConnectParams() -dbParams.setPort(DBSetting.port) -dbParams.setUser(DBSetting.user) -dbParams.setPassword(DBSetting.password) - -dbMan = DBManager() -dbMan.connect(dbParams) -dbMan.getWaitingAccountList() \ No newline at end of file +checker = UnpaidMaestroChecker() +week1MaestroList = checker.getUnpaid7daysMaestroList() +for maestroData in week1MaestroList: + maestroId = maestroData['MaestroID'] + name = maestroData['Name'] + email = maestroData['Email'] + registeredDateTime = maestroData['AcceptClausesDateTime'] + availableDateTime = maestroData['AvailableActivateDateTime'] + print("{0}, {1}, {2}, {3}, {4}" \ + .format(maestroId, name, email, availableDateTime, registeredDateTime)) diff --git a/src/web/python/batch/unpaid_maestro_checker.py b/src/web/python/batch/unpaid_maestro_checker.py new file mode 100644 index 0000000..0bf913b --- /dev/null +++ b/src/web/python/batch/unpaid_maestro_checker.py @@ -0,0 +1,23 @@ +from db_setting import DBSetting +from db_manager import DBConnectParams, DBManager + +class UnpaidMaestroChecker: + dbParams = None + dbMan = None + + unpaid7daysSql = "select * from maestro \ + where DATE(NOW()) - INTERVAL 7 DAY > AcceptClausesDateTime AND ActivateStatus = 0" + + def __init__(self): + self.dbParams = DBConnectParams() + self.dbParams.port = DBSetting.port + self.dbParams.user = DBSetting.user + self.dbParams.password = DBSetting.password + + self.dbMan = DBManager() + self.dbMan.connect(self.dbParams) + + def getUnpaid7daysMaestroList(self): + day7MaestroList = self.dbMan.select(self.unpaid7daysSql) + self.dbMan.close() + return day7MaestroList \ No newline at end of file