# -*- coding: utf-8 -*-
import re
建立相關表的字段
從源表建立指定的mysql建表指令碼
# 目標表名稱 lzb_decoration_houseinfo
table_name = 'lzb_decoration_audit'
# 原表名稱
original_table_name="decorationaudit"
print("#drop table if exists ;".format(table_name))
print("create table (".format(table_name))
print("id bigint(20) unsigned not null auto_increment")
with open('sql_server_table_source', encoding='utf-8') as f:
for line in f.readlines():
#print(line)
if line=='\n':
continue
if re.match('.*(not.*null).*', line) is none:
if re.match('.*(.*null.*).*',line) is not none:
line = line.replace("null", " not null ")
#print(line)
# 獲取注釋
str_comment='未知'
list_comment=re.findall(r".*,(.*)",line)
if len(list_comment)==1:
str_comment=list_comment[0].strip()
# 獲取注釋後的字元
temp_line_list=re.findall(r"(.*),.*",line)
if temp_line_list is none or temp_line_list=="" or len(temp_line_list)==0:
continue
temp_line=temp_line_list[0]
# unrenow_reason varchar(512)
prefix_line=re.sub(r'(\[.*\])','',temp_line).strip()
#print(prefix_line)
#str_comment=re.sub("(\,)","",str_comment)
if re.match(r'.*int.*', prefix_line, flags=0) is not none:
print(","+prefix_line+" "+"not null "+"comment '"+str_comment.strip()+"'")
continue
if re.match(r'.*decimal.*', prefix_line, flags=0) is not none:
print("," + prefix_line +"(18,2)"+ " " + "not null " + "comment '" + str_comment.strip() + "'")
continue
if re.match(r'.*datetime.*', prefix_line, flags=0) is not none:
print("," + prefix_line + " " + "not null " + "comment '" + str_comment.strip() + "'")
continue
if re.match(r'.*varchar.*', prefix_line, flags=0) is not none:
print("," + prefix_line + " " + "not null default ''" + "comment '" + str_comment.strip() + "'")
continue
print(",ts bigint not null default 0 comment '源表時間戳' ")
print(",sync_time datetime not null default current_timestamp comment '從原表同步到報表的時間'")
print(",modify_time datetime not null comment '最後更新時間'")
print(",primary key (id)")
print(') engine=innodb auto_increment=0 default charset=utf8;')
print("\n\n\n\n")
print("同步kettle指令碼")
print("select ")
with open('sql_server_table_source', encoding='utf-8') as f:
for line in f.readlines():
if line=='\n':
continue
str_original_field = ""
field_original_reg=re.findall(".*\[(.*)\].*",line)
if field_original_reg is not none:
str_original_field=field_original_reg[0]
result_field_nvarchar=re.findall('.*\](.*)\s*nvarchar.*',line)
is_nvarchar_field=false
is_bigint_field=false
str_target_field=""
if result_field_nvarchar is not none and len(result_field_nvarchar)>0:
str_target_field=result_field_nvarchar[0]
is_nvarchar_field=true
else:
result = re.findall('.*\](.*)(int|varchar|datetime|bigint|decimal|nvarchar).*', line)
if result is not none and len(result)!=0 and len(result[0])!=0:
str_target_field=result[0][0].strip()
if re.match('.*(bigint).*', line) is not none:
result_field_bigint = re.findall('.*\](.*)\s*bigint.*', line)
str_target_field=result_field_bigint[0].strip()
if is_nvarchar_field or re.match(r".*(varchar).*", line) is not none:
print("isnull(t.,'') as ,".format(str_original_field,str_target_field))
elif is_bigint_field:
print("isnull(t.,0) as ,".format(str_original_field, str_target_field))
elif re.match('.*(bigint).*',line) is not none or re.match(r".*(int|bigint|decimal).*",line) is not none:
print("isnull(t.,0) as ,".format(str_original_field, str_target_field))
elif re.match(r".*(datetime|date).*",line) is not none:
print("isnull(t.,'1970-01-01') as ,".format(str_original_field, str_target_field))
elif re.match(r".*(bit).*",line) is not none:
print("isnull(t.,0) as ,".format(str_original_field, str_target_field))
else :
print("error")
print(" getdate() as sync_time ,")
print(" getdate() as modify_time , ")
print("isnull(t.ts,0) as ts ")
print(" from as t with(nolock) where t.ts> ? ".format(original_table_name))
pytho指令碼學習
http狀態碼獲取 2.1響應狀態碼 2.2測試 https 2.3http協議 2.3.1埠80 http1.1 多次可以乙個連線 2.3.2明文傳輸 2.4https 443埠加密傳輸 2.5請求方法 2.5.2http1.1 put delete trace conmect patch增加了檔...
Android Apk反編譯指令碼(python)
usr bin env python3 import os if main name print python start n 請確保apktool.jar和apk在同一資料夾內 in temp input 請輸入指令 f 反編譯 n if in temp f print 開始反編譯 apk pat...
生產mysqldump備份指令碼
1.記錄日誌功能 2.傳參的情況可以實現單庫備份 3.無傳參實現全庫備份 1.會警告命令列輸入密碼不安全,mysql 5.5以上的版本 2.mysqldump是冷備會造成資料不一致,備份時候可以指定鎖全表備份 3.在迴圈備份到最後乙個庫的時候可以加 flush logs 引數,日誌滾動 1.備份盡量...