修改mysql数据

import time

import pymysql
import schedule


def job():
    # 连接数据库
    connect = pymysql.Connect(
        host='140.210.4.73',
        port=3306,
        user='twipad_cj',
        passwd='bj@#twipad_cj',
        db='tw_ipaddb',
        charset='utf8mb4'
    )
    cursor = connect.cursor()
    try:
        sql1 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝" where ir_keyword="国民党"'
        sql2 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="绿党"'
        sql3 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="民进党"'
        sql4 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="社会民主党"'
        sql5 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="时代力量"'
        sql6 = 'update hkby_facebookhistory_abroaddataall set ir_camp="红统派" where ir_keyword="亲民党"'
        sql7 = 'update hkby_facebookhistory_abroaddataall set ir_camp="红统派" where ir_keyword="统促党"'
        sql8 = 'update hkby_facebookhistory_abroaddataall set ir_camp="红统派" where ir_keyword="新党"'
        sql9 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝" where ir_keyword="致公党"'
        sql10 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="郝龙斌"'
        sql11 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="台北市" where ir_keyword="蔡正元"'
        sql12 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="台中市" where ir_keyword="江启臣"'
        sql13 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="高雄市" where ir_keyword="3Q 陈柏惟"'
        sql14 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="花莲县" where ir_keyword="徐榛蔚"'
        sql15 = 'update hkby_facebookhistory_abroaddataall set ir_camp="其他",ir_from="台北市" where ir_keyword="柯文哲"'
        sql16 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="朱立伦"'
        sql17 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="新北市" where ir_keyword="侯友宜"'
        sql18 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="台北市" where ir_keyword="姚文智"'
        sql19 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="段宜康"'
        sql20 = 'update hkby_facebookhistory_abroaddataall set ir_camp="其他",ir_from="其他" where ir_keyword="陈建仁 Chen Chien-Jen"'
        sql21 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="高雄市" where ir_keyword="赵天麟"'
        sql22 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="台中市" where ir_keyword="蔡其昌"'
        sql23 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="花莲县" where ir_keyword="萧美琴"'
        sql24 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="郭正亮"'
        sql25 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="新北市" where ir_keyword="黄国昌"'
        sql26 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="台北市" where ir_keyword="林昶佐 Freddy Lim"'
        sql27 = 'update hkby_facebookhistory_abroaddataall set ir_camp="红统派",ir_from="其他" where ir_keyword="王炳忠"'
        sql28 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="蔡英文 Tsai Ing-wen"'
        sql29 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="高雄市" where ir_keyword="韩国瑜"'
        sql30 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="陈水扁(Chen Shui-bian)"'
        sql31 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="马英九"'
        sql32 = 'update hkby_facebookhistory_abroaddataall set ir_camp="其他",ir_from="彰化县" where ir_keyword="林全"'
        sql33 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="萧万长"'
        sql34 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="洪秀柱"'
        sql35 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="台北市" where ir_keyword="罗智强"'
        sql36 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="新北市" where ir_keyword="苏贞昌"'
        sql37 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="谢长廷"'
        sql38 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="其他" where ir_keyword="游锡堃"'
        sql39 = 'update hkby_facebookhistory_abroaddataall set ir_camp="红统派",ir_from="其他" where ir_keyword="邱毅"'
        sql40 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="台中市" where ir_keyword="林佳龙"'
        sql41 = 'update hkby_facebookhistory_abroaddataall set ir_camp="其他",ir_from="金门县" where ir_keyword="陈福海"'
        sql42 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="屏东县" where ir_keyword="曾永权"'
        sql43 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="其他" where ir_keyword="王育敏"'
        sql44 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="新竹市" where ir_keyword="林智坚"'
        sql45 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="桃园市" where ir_keyword="郑文灿"'
        sql46 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿",ir_from="高雄市" where ir_keyword="陈其迈"'
        sql47 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="公投护台湾联盟"'
        sql48 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="基进党"'
        sql49 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="台联党"'
        sql50 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="新境界文教基金会"'
        sql51 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛绿" where ir_keyword="自由台湾党"'
        sql52 = 'update hkby_facebookhistory_abroaddataall set ir_camp="泛蓝",ir_from="台北市" where ir_keyword="费鸿泰(阿力克司)"'


        cursor.execute(sql1)
        cursor.execute(sql2)
        cursor.execute(sql3)
        cursor.execute(sql4)
        cursor.execute(sql5)
        cursor.execute(sql6)
        cursor.execute(sql7)
        cursor.execute(sql8)
        cursor.execute(sql9)
        cursor.execute(sql10)
        cursor.execute(sql11)
        cursor.execute(sql12)
        cursor.execute(sql13)
        cursor.execute(sql14)
        cursor.execute(sql15)
        cursor.execute(sql16)
        cursor.execute(sql17)
        cursor.execute(sql18)
        cursor.execute(sql19)
        cursor.execute(sql20)
        cursor.execute(sql21)
        cursor.execute(sql22)
        cursor.execute(sql23)
        cursor.execute(sql24)
        cursor.execute(sql25)
        cursor.execute(sql26)
        cursor.execute(sql27)
        cursor.execute(sql28)
        cursor.execute(sql29)
        cursor.execute(sql30)
        cursor.execute(sql31)
        cursor.execute(sql32)
        cursor.execute(sql33)
        cursor.execute(sql34)
        cursor.execute(sql35)
        cursor.execute(sql36)
        cursor.execute(sql37)
        cursor.execute(sql38)
        cursor.execute(sql39)
        cursor.execute(sql40)
        cursor.execute(sql41)
        cursor.execute(sql42)
        cursor.execute(sql43)
        cursor.execute(sql44)
        cursor.execute(sql45)
        cursor.execute(sql46)
        cursor.execute(sql47)
        cursor.execute(sql48)
        cursor.execute(sql49)
        cursor.execute(sql50)
        cursor.execute(sql51)
        cursor.execute(sql52)

        connect.commit()
        print('修改成功')
    except:
        print('暂无数据')

    connect.close()

job()
# if __name__ == '__main__':
#     while 1:
#         # 每两秒执行一次
#         schedule.every().day.at("11:00").do(job)
#         schedule.run_pending()

  

posted @ 2021-09-13 16:21  布都御魂  阅读(51)  评论(0)    收藏  举报