Add: unpaid maestro db work
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import datetime
|
||||
import time
|
||||
import pymysql
|
||||
from db_setting import DBSetting
|
||||
|
||||
|
||||
class DBConnectParams:
|
||||
@@ -14,56 +16,51 @@ class DBConnectParams:
|
||||
|
||||
class DBManager:
|
||||
def __init__(self):
|
||||
print('init')
|
||||
self.conn = None
|
||||
self.curs = None
|
||||
self.db_params = DBConnectParams()
|
||||
self.db_params = DBConnectParams()
|
||||
self.db_params.port = DBSetting.port
|
||||
self.db_params.user = DBSetting.user
|
||||
self.db_params.password = DBSetting.password
|
||||
super().__init__()
|
||||
|
||||
def close(self):
|
||||
print('close')
|
||||
self.conn.close()
|
||||
|
||||
def connect(self, dbParam):
|
||||
def connect(self):
|
||||
self.conn = pymysql.connect(
|
||||
host=dbParam.host, port=dbParam.port,
|
||||
user=dbParam.user, password=dbParam.password,
|
||||
db=dbParam.db, charset=dbParam.charset)
|
||||
self.curs = self.conn.cursor(pymysql.cursors.DictCursor)
|
||||
host=self.db_params.host, port=self.db_params.port,
|
||||
user=self.db_params.user, password=self.db_params.password,
|
||||
db=self.db_params.db, charset=self.db_params.charset)
|
||||
|
||||
def select(self, sql):
|
||||
self.curs.execute(sql)
|
||||
self.execute_sql(sql, [])
|
||||
self.conn.close()
|
||||
rows = self.curs.fetchall()
|
||||
return rows
|
||||
|
||||
def insert(self, sql, params):
|
||||
self.execute_sql(sql, params)
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
def update(self, sql, params):
|
||||
self.execute_sql(sql, params)
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
def delete(self, sql, params):
|
||||
self.execute_sql(sql, params)
|
||||
self.conn.commit()
|
||||
self.conn.close()
|
||||
|
||||
def execute_sql(self, sql, params):
|
||||
self.connect()
|
||||
self.curs = self.conn.cursor(pymysql.cursors.DictCursor)
|
||||
# print(type(sql))
|
||||
# print(sql)
|
||||
# print(type(params))
|
||||
# print(params)
|
||||
self.curs.execute(sql, params)
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
'''
|
||||
def get_waiting_account_list(self):
|
||||
sql = "select * from maestro"
|
||||
self.curs.execute(sql)
|
||||
rows = self.curs.fetchall()
|
||||
|
||||
today = datetime.datetime.today()
|
||||
before_7days= today - datetime.timedelta(days=7)
|
||||
|
||||
for row in rows:
|
||||
name = row['Name']
|
||||
registered_datetime = row['AcceptClausesDateTime']
|
||||
available_datetime = row['AvailableActivateDateTime']
|
||||
# print(type(registeredDateTime))
|
||||
|
||||
if type(available_datetime) is str and before_7days >= registered_datetime:
|
||||
print("{0}, {1}, {2}".format(name, available_datetime, registered_datetime))
|
||||
'''
|
||||
@staticmethod
|
||||
def get_datetime_now():
|
||||
return time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
@@ -1,36 +1,43 @@
|
||||
from unpaid_maestro_checker import UnpaidMaestroChecker
|
||||
from unpaid_maestro_manager import UnpaidMaestroManager
|
||||
from mail_sender import NCloud
|
||||
from mail_sender import MailSender
|
||||
|
||||
|
||||
def send_mail_for_test(name, email, register_date):
|
||||
def test_send_mail():
|
||||
MailSender.send_temp_mail()
|
||||
return
|
||||
|
||||
maestro_name = 'test1'
|
||||
maestro_email = 'jisangs@daum.net'
|
||||
params = {'maestro_name': maestro_name, 'maestro_date': '2019-04-08'}
|
||||
|
||||
mail_sender = MailSender()
|
||||
mail_sender.make_default_post_param()
|
||||
mail_sender.set_post_param('templateSid', 337)
|
||||
mail_sender.set_post_param_recipients(name, email)
|
||||
mail_sender.set_post_param('parameters',
|
||||
{'maestro_name': name, 'maestro_date': register_date })
|
||||
mail_sender.set_post_param_recipients(maestro_name, maestro_email)
|
||||
mail_sender.set_post_param('parameters', params)
|
||||
|
||||
timestamp = MailSender.get_timestamp()
|
||||
# print('hmac : ' + MailSender.hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret'))
|
||||
signature = MailSender.make_signature(NCloud.request_url, timestamp)
|
||||
# print('signature : ' + signature.decode('utf-8'))
|
||||
# print('signature : ' + signature)
|
||||
# mail_sender.send_email(timestamp, signature)
|
||||
MailSender.send_temp_mail()
|
||||
|
||||
mail_sender = MailSender()
|
||||
send_mail_for_test('test1', 'jisangs@daum.net', '2019-04-08')
|
||||
mail_sender.send_email(timestamp, signature)
|
||||
|
||||
|
||||
'''
|
||||
checker = UnpaidMaestroChecker()
|
||||
day7MaestroList = checker.get_unpaid_7days_maestro_list()
|
||||
for maestro_data in day7MaestroList:
|
||||
maestro_id = maestro_data['MaestroID']
|
||||
name = maestro_data['Name']
|
||||
email = maestro_data['Email']
|
||||
registered_dateTime = maestro_data['AcceptClausesDateTime']
|
||||
available_dateTime = maestro_data['AvailableActivateDateTime']
|
||||
print("{0}, {1}, {2}, {3}, {4}" \
|
||||
.format(maestro_id, name, email, available_dateTime, registered_dateTime))
|
||||
'''
|
||||
def test_db_work():
|
||||
unpaid_maestro_manager = UnpaidMaestroManager()
|
||||
day7_maestro_list = unpaid_maestro_manager.get_unpaid_7days_maestro_list()
|
||||
# print(day7_maestro_list)
|
||||
maestro_list = list()
|
||||
maestro_list.append(day7_maestro_list[0])
|
||||
# print(maestro_list)
|
||||
for maestro in maestro_list:
|
||||
maestro_id = maestro['MaestroID']
|
||||
maestro_name = maestro['Name']
|
||||
remark = maestro_name + ' / ' + 'unpaid 7 days'
|
||||
unpaid_maestro_manager.insert_maestro_log(maestro_id, remark)
|
||||
unpaid_maestro_manager.delete_maestro(maestro_id)
|
||||
|
||||
|
||||
test_send_mail()
|
||||
# test_db_work()
|
||||
@@ -1,31 +0,0 @@
|
||||
from db_setting import DBSetting
|
||||
from db_manager import DBConnectParams, DBManager
|
||||
|
||||
|
||||
class UnpaidMaestroChecker:
|
||||
dbParams = None
|
||||
dbMan = None
|
||||
|
||||
unpaid_7days_sql = "select * from maestro \
|
||||
where DATE(NOW()) - INTERVAL 7 DAY > AcceptClausesDateTime AND ActivateStatus = 0"
|
||||
unpaid_8days_sql = "select * from maestro \
|
||||
where DATE(NOW()) - INTERVAL 8 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 get_unpaid_7days_maestro_list(self):
|
||||
day7_maestro_list = self.dbMan.select(self.unpaid_7days_sql)
|
||||
self.dbMan.close()
|
||||
return day7_maestro_list
|
||||
|
||||
def get_unpaid_8days_maestro_list(self):
|
||||
day8_maestro_list = self.dbMan.select(self.unpaid_8days_sql)
|
||||
self.dbMan.close()
|
||||
return day8_maestro_list
|
||||
@@ -0,0 +1,37 @@
|
||||
from db_manager import DBConnectParams
|
||||
from db_manager import DBManager
|
||||
|
||||
|
||||
class UnpaidMaestroManager:
|
||||
db_params = None
|
||||
db_man = None
|
||||
|
||||
def __init__(self):
|
||||
self.db_man = DBManager()
|
||||
|
||||
def get_unpaid_7days_maestro_list(self):
|
||||
unpaid_7days_sql = 'select * from maestro \
|
||||
where DATE(NOW()) - INTERVAL 7 DAY > AcceptClausesDateTime AND ActivateStatus = 0'
|
||||
day7_maestro_list = self.db_man.select(unpaid_7days_sql)
|
||||
return day7_maestro_list
|
||||
|
||||
def get_unpaid_8days_maestro_list(self):
|
||||
unpaid_8days_sql = 'select * from maestro \
|
||||
where DATE(NOW()) - INTERVAL 8 DAY > AcceptClausesDateTime AND ActivateStatus = 0'
|
||||
day8_maestro_list = self.db_man.select(unpaid_8days_sql)
|
||||
return day8_maestro_list
|
||||
|
||||
def insert_maestro_log(self, maestro_id, remark):
|
||||
sql = 'INSERT INTO maestro_log (Type, MaestroID, LogDateTime, Remark) \
|
||||
VALUES (\'delete_maestro\', %s, %s, %s)'
|
||||
params = (maestro_id, DBManager.get_datetime_now(), remark)
|
||||
# print(sql)
|
||||
# print(params)
|
||||
self.db_man.insert(sql, params)
|
||||
|
||||
def delete_maestro(self, maestro_id):
|
||||
sql = 'DELETE FROM maestro WHERE MaestroID = %s'
|
||||
params = (maestro_id)
|
||||
# print(sql)
|
||||
# print(params)
|
||||
self.db_man.delete(sql, params)
|
||||
Reference in New Issue
Block a user