From f96b713d2b17aecae6866511a36916f20db51c57 Mon Sep 17 00:00:00 2001 From: pengtao Date: Wed, 18 Sep 2019 16:04:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0DN=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=8F=8A=E6=96=B0=E5=A2=9E=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=20test1=20=E7=94=A8=E4=BA=8E=E9=AA=8C=E8=AF=81=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prod_config.py | 6 ++++ redis/change_db.py | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 redis/change_db.py diff --git a/prod_config.py b/prod_config.py index 1b622c9..04bfe2a 100644 --- a/prod_config.py +++ b/prod_config.py @@ -21,6 +21,12 @@ elif myenv == 'test': log_path = "/data/logs/test/" ad_list_interface_port = 6014 priv_i_port=6015 +elif myenv == 'test1': + redis_company_config = {'host': '10.10.4.8', 'port': 6379, 'db': 12, 'passwd': 'crs-9ltb97ds:i33dkxshh'} + mysql_promotion_config = {'user': 'ad', 'pswd': ad_mysql_pwd, 'host': '10.10.3.5', 'db': 'test1'} + log_path = "/data/logs/test/" + ad_list_interface_port = 6014 + priv_i_port=6015 else: raise Exception("GET config with mysql/redis failed!") diff --git a/redis/change_db.py b/redis/change_db.py new file mode 100644 index 0000000..3b50fb5 --- /dev/null +++ b/redis/change_db.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +from mysql.mmysql import MysqlBase +import copy +import pdb + +old_db = {'user': 'ad', 'pswd': "vF4j56AfxU3P", 'host': '10.10.3.5', 'db': 'ad'} +new_db = {'user': 'ad', 'pswd': "vF4j56AfxU3P", 'host': '10.10.3.5', 'db': 'test1'} + +old = MysqlBase(**old_db) +new = MysqlBase(**new_db) + + +def get_old_ad(): + old_data = [] + sql = "SELECT id,name,gameid,channelid,locationid,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param," \ + "ad_property,ad_sort,jump_status,status,in_used,companyid,createtime FROM `ad` ; " + data = old.query(sql) + if data: + for line in data: + if line: + temp = {} + temp['id'], temp['name'], temp['gameid'], temp['channelid'], temp['locationid'], temp['begin_time'], \ + temp['end_time'], temp['ad_num'], temp['ad_title'], temp['ad_body'], temp['ad_image'], temp[ + 'jump_param'], temp['ad_property'], temp['ad_sort'], temp['jump_status'], temp['status'], temp[ + 'in_used'], temp['companyid'], temp['createtime'] = line + old_data.append(temp) + del temp + return old_data + + +def write_ad_data(data): + for line in data: + table_name = "ad" + try: + new.insert(table_name, line) + except Exception: + print(f"write {line} 2 ad failed!") + + +def get_old_location(): + location_data = [] + sql = "SELECT id,area,gameid,channelid,type,mode,in_used,createtime FROM `location` " + data = old.query(sql) + if data: + for line in data: + if line: + temp = {} + temp['id'], temp['area'], temp['gameid'], temp['channelid'], temp['type'], temp['mode'], temp[ + 'in_used'], temp['createtime'] = line + temp['ld_property'] = "" + try: + + area_old = copy.deepcopy(temp['area']) + if len(area_old.split(',')) != 5: + print(f"area can`t split {area_old}") + else: + temp['x'] = area_old.split(',')[1] + temp['y'] = area_old.split(',')[2] + temp['x_offset'] = area_old.split(',')[3] + temp['y_offset'] = area_old.split(',')[4] + temp['area'] = f"[{area_old.split(',')[0]}]" + location_data.append(temp) + del temp + except Exception: + print(f"split area failed,area={temp['area']} ") + return location_data + + +def write_location(data): + for line in data: + table_name = "location" + try: + new.insert(table_name, line) + except Exception: + print(f"write {line} 2 location failed!") + + +def main(): + old_ad = get_old_ad() + write_ad_data(old_ad) + old_location = get_old_location() + write_location(old_location) + + +if __name__ == "__main__": + main()