Add: backup_unregister_maestro.py
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
from batch.unpaid_maestro_manager import UnpaidMaestroManager
|
||||
|
||||
|
||||
# print('# args : {}'.format(len(sys.argv)))
|
||||
# print('args : {}'.format(str(sys.argv)))
|
||||
mode = 'mac'
|
||||
arg_count = len(sys.argv)
|
||||
if arg_count > 1:
|
||||
mode = str(sys.argv[1]).lower();
|
||||
|
||||
|
||||
def print_items(list):
|
||||
for item in list:
|
||||
print(item)
|
||||
|
||||
|
||||
def backup_unregister_maestro_table_file():
|
||||
space = ' '
|
||||
command = 'mysqldump' + space
|
||||
user = '-u root' + space
|
||||
password = '-p52napark!' + space
|
||||
transaction = '--single-transaction' + space
|
||||
db = 'chocomae' + space
|
||||
table = 'maestro' + space
|
||||
where_clause = '--where="DATE(NOW()) - INTERVAL 7 DAY > AcceptClausesDateTime AND ActivateStatus = 0"' + space
|
||||
output_directory = '/home/chocomae/unregister-user-backup/'
|
||||
if mode == 'mac':
|
||||
output_directory = ''
|
||||
today = datetime.today().strftime('%Y%m%d-%H%M%S')
|
||||
output_filename = '> ' + today + '.sql'
|
||||
|
||||
command_db_backup = command + user + password + transaction + db + table + where_clause \
|
||||
+ output_directory + output_filename
|
||||
# 'mysqldump -u "${DBUSER}" -p"${DBPASS}" --single-transaction "${DBNAME}" "${filename}" --where="DATE(${record_date})=CURDATE()" > "${filename}.dump.bydate.sql"'
|
||||
print(command_db_backup)
|
||||
subprocess.call(command_db_backup)
|
||||
|
||||
|
||||
unpaidMaestroMan = UnpaidMaestroManager(mode)
|
||||
maestro_list = unpaidMaestroMan.get_unpaid_7days_maestro_list()
|
||||
print_items(maestro_list)
|
||||
|
||||
backup_unregister_maestro_table_file()
|
||||
|
||||
# print(mode)
|
||||
'''
|
||||
for maestro in maestro_list:
|
||||
remark = maestro['Name'] + ' / unpaid 7 days'
|
||||
unpaidMaestroMan.insert_maestro_log(maestro['MaestroID'], remark)
|
||||
unpaidMaestroMan.delete_maestro_list(maestro['MaestroID'])
|
||||
'''
|
||||
@@ -5,8 +5,8 @@ class UnpaidMaestroManager:
|
||||
db_params = None
|
||||
db_man = None
|
||||
|
||||
def __init__(self):
|
||||
self.db_man = DBManager()
|
||||
def __init__(self, mode):
|
||||
self.db_man = DBManager(mode)
|
||||
|
||||
def get_unpaid_7days_maestro_list(self):
|
||||
unpaid_7days_sql = 'select * from maestro \
|
||||
@@ -28,7 +28,7 @@ VALUES (\'delete_maestro\', %s, %s, %s)'
|
||||
# print(params)
|
||||
self.db_man.insert(sql, params)
|
||||
|
||||
def delete_maestro(self, maestro_id):
|
||||
def delete_maestro_list(self, maestro_id):
|
||||
sql = 'DELETE FROM maestro WHERE MaestroID = %s'
|
||||
params = (maestro_id)
|
||||
# print(sql)
|
||||
|
||||
@@ -3,32 +3,18 @@ import pymysql
|
||||
from lib.database.db_setting import DBSetting
|
||||
|
||||
|
||||
class DBConnectParams:
|
||||
def __init__(self):
|
||||
self.host = 'localhost'
|
||||
self.port = 3306
|
||||
self.user = ''
|
||||
self.password = ''
|
||||
self.db = 'chocomae'
|
||||
self.charset = 'utf8'
|
||||
|
||||
|
||||
class DBManager:
|
||||
def __init__(self):
|
||||
def __init__(self, mode):
|
||||
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__()
|
||||
self.db_setting = DBSetting(mode)
|
||||
# super().__init__()
|
||||
|
||||
def connect(self):
|
||||
self.conn = pymysql.connect(
|
||||
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)
|
||||
host=self.db_setting.host, port=self.db_setting.port,
|
||||
user=self.db_setting.user, password=self.db_setting.password,
|
||||
db=self.db_setting.db, charset=self.db_setting.charset)
|
||||
|
||||
def select(self, sql):
|
||||
self.execute_sql(sql, [])
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
class DBSetting:
|
||||
host = 'localhost'
|
||||
user = 'jisangs'
|
||||
user = ''
|
||||
password = ''
|
||||
db = 'chocomae'
|
||||
port = 0
|
||||
charset = 'utf8'
|
||||
|
||||
# service, test server
|
||||
# port = 3306
|
||||
# password = '52napark!'
|
||||
|
||||
# mac
|
||||
port = 8889
|
||||
password = 'Fr12nds95'
|
||||
def __init__(self, mode):
|
||||
if mode == 'mac':
|
||||
self.user = 'jisangs'
|
||||
self.password = 'Fr12nds95'
|
||||
self.port = 8889
|
||||
elif mode == 'test':
|
||||
self.user = 'root'
|
||||
self.password = '52napark!'
|
||||
self.port = 3306
|
||||
elif mode == 'service':
|
||||
self.user = 'root'
|
||||
self.password = '52napark!'
|
||||
self.port = 3306
|
||||
|
||||
@@ -9,5 +9,5 @@ maestro_list = umMan.get_unpaid_7days_maestro_list()
|
||||
# print(item)
|
||||
'''
|
||||
|
||||
mailSender = MailSenderExample()
|
||||
mailSender.send_temp_mail()
|
||||
# mailSender = MailSenderExample()
|
||||
# mailSender.send_temp_mail()
|
||||
Reference in New Issue
Block a user