国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

python - 怎么寫一個腳本可以清除數(shù)據(jù)庫里的某行測試數(shù)據(jù)

瀏覽:110日期:2022-07-19 16:26:49

問題描述

就是要寫個腳本 數(shù)據(jù)庫有測試用的手機號 注冊完數(shù)據(jù)庫里會有一大堆相關(guān)的數(shù)據(jù) 然后腳本就需要能清除這些數(shù)據(jù) 或者將它們設(shè)置為null 這個是類似的一個腳本 應該怎么修改

from future import print_functionimport itertoolsimport pymysql.cursorsimport csv

from utils import is_telephone, is_email

if name == ’__main__’:sg_connection = pymysql.connect(host=’localhost’,user=’root’,password=’root’,db=’sellergrowth’,charset=’utf8’,cursorclass=pymysql.cursors.DictCursor)

uc_connection = pymysql.connect(host=’localhost’,user=’root’,password=’root’,db=’sguc’,charset=’utf8’,cursorclass=pymysql.cursors.DictCursor)

def _filter_valid(entity):if not entity[’username’]:return Falseif entity[’telephone’] and not is_telephone(entity[’telephone’]):return Falseif entity[’email’] and not is_email(entity[’email’]):return Falseif not ((entity[’telephone’] and entity[’telephone_verified’]) or (entity[’email’] and entity[’email_verified’])):return Falsereturn True

def _map_to_correct(entity):def _set_blank_to_none(name):if not entity[name]:entity[name] = None

_set_blank_to_none(’telephone’)_set_blank_to_none(’email’)if entity[’telephone’] and not entity[’telephone_verified’]:entity[’telephone’] = Noneif entity[’email’] and not entity[’email_verified’]:entity[’email’] = None_set_blank_to_none(’password’)_set_blank_to_none(’wechat_unionid’)_set_blank_to_none(’wechat_app_openid’)_set_blank_to_none(’wechat_public_openid’)_set_blank_to_none(’wechat_site_openid’)_set_blank_to_none(’qq_openid’)_set_blank_to_none(’last_login’)_set_blank_to_none(’sign_url’)_set_blank_to_none(’user_uuid’)if not entity[’signup_service_id’]:entity[’signup_service_id’] = 11300if entity[’signup_method’] == 1:entity[’signup_method’] = ’MOBILE’elif entity[’signup_method’] == 2:entity[’signup_method’] = ’TABLET’elif entity[’signup_method’] == 3:entity[’signup_method’] = ’WE_CHAT_PUBLIC’elif entity[’signup_method’] == 4:entity[’signup_method’] = ’WE_CHAT_SITE’elif entity[’signup_method’] == 12:entity[’signup_method’] = ’WE_CHAT_APP’elif entity[’signup_method’] == 6:entity[’signup_method’] = ’QQ_WEB’elif entity[’signup_method’] == 7:entity[’signup_method’] = ’QQ_WEBAPP’else:entity[’signup_method’] = Noneentity[’is_active’] = 1 if entity[’is_active’] else 0return entity

def _dict_to_tuple(entity):return tuple((entity[’telephone’], entity[’email’], entity[’username’], entity[’password’], entity[’wechat_unionid’],entity[’wechat_app_openid’],entity[’wechat_public_openid’], entity[’wechat_site_openid’], entity[’qq_openid’],int(entity[’signup_service_id’]), entity[’date_joined’], entity[’last_login’], entity[’is_active’],entity[’signup_method’], entity[’sign_url’], entity[’user_uuid’]))

try:with sg_connection.cursor() as cursor, uc_connection.cursor() as uc_cursor:sql = ’SELECT is_active, p.telephone, email, username, password, p.wechat_unionid, p.wechat_app_openid, p.wechat_public_openid, p.wechat_site_openid, p.qq_openid, p.signup_service_id, p.telephone_verified, p.email_verified, date_joined, last_login, p.signup_method, e.sign_url, p2.user_uuid FROM account_profile p LEFT JOIN event_baseevent e ON e.id=p.signup_event_id LEFT JOIN account_profile p2 ON p2.user_id=p.inviter_id, auth_user u WHERE p.user_id=u.id’cursor.execute(sql)cursor, cursor_for_record = itertools.tee(cursor)cursor = itertools.ifilter(_filter_valid, cursor)cursor = itertools.imap(_map_to_correct, cursor)cursor = itertools.imap(_dict_to_tuple, cursor)

sql = ’INSERT into cas_service (service_id, service_group) VALUES (%s, %s)’service_list = ((11300, ’SG’), (12300, ’SGASK’), (13300, ’YQSXY’), (14300, ’CHUANGLAN’))uc_cursor.executemany(sql, service_list)uc_connection.commit()

insert_sql = ’INSERT into cas_user (phone, email, username1, password1, wechat_unionid, wechat_app_openid, wechat_public_openid, wechat_site_openid, qq_openid, sign_up_service_id, date_joined, last_login, is_active, sign_up_device, sg_event_url, sg_inviter_uid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)’uc_cursor.executemany(insert_sql, list(cursor))uc_connection.commit()

with open(’not_migration_report.csv’, ’wb’) as csvfile:spamwriter = csv.writer(csvfile, delimiter=’,’, quotechar=’|’, quoting=csv.QUOTE_MINIMAL)init = Falsecursor_for_record = itertools.ifilterfalse(_filter_valid, cursor_for_record)for i in cursor_for_record:if not init:init = Trueprint(i.keys())spamwriter.writerow([a.encode('utf8') if type(a) == unicode else a for a in i.values()])finally:sg_connection.close()uc_connection.close()

問題解答

回答1:

如果對表有操作權(quán)限的話 只需要 增加一個標識狀態(tài)的flag即可 如 flag = test

DELETE * FROM table_name WHERE flag = test

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 一区二区三区高清视频在线观看 | 艳女伦交一级毛片 | 亚洲视频天堂 | 日韩a级毛片免费视频 | 国产三级a三级三级三级 | 国产91会所洗浴女技师按摩 | 亚州精品一区二区三区 | 波多野结衣在线视频观看 | 国产精品久久国产三级国电话系列 | 杨幂精品国产专区91在线 | 日韩精品一区二区三区不卡 | 亚洲欧美一区二区三区在线播放 | 亚洲第一区香蕉_国产a | 特级黄色毛片视频 | 国产成人精品视频免费大全 | 日韩午夜在线观看 | 亚洲精品色 | 中文字幕乱码系列免费 | 国产成人精品一区二区三在线观看 | 777色狠狠一区二区三区 | 久久综合久久美利坚合众国 | 自怕偷自怕亚洲精品 | 欧美一级一一特黄 | 日本波多野结衣视频 | 亚洲最大网站在线 | 67id人成国产在线 | 国产精品毛片天天看片 | 天堂mv亚洲mv在线播放9蜜 | 日本乱人伦片中文字幕三区 | 亚洲精品视频区 | 男人的天堂官网 | 视频一区二区在线 | 亚洲国产第一区二区三区 | 国产毛片一区二区三区精品 | 国内精品久久久久久久亚洲 | 亚洲天堂手机在线 | 国产91会所洗浴女技师按摩 | 日韩一级片在线观看 | 国产香蕉久久 | 久久成人动漫 | 欧美在线精品一区二区三区 |