#!/usr/bin/env python # encoding: utf-8 import pymysql from config.config import * import datetime def get_conn(): conn=pymysql.connect(host=HOST,port=PORT,user=USER,passwd=PASSWORD,db=DB,charset=CHARSET, cursorclass=pymysql.cursors.DictCursor) return conn def get_idlist(): datalist=[] conn=get_conn() try: with conn.cursor() as cursor: sql="select PAGE_CD,PAGE_NAME from sns_page where PAGE_ID in(%s,%s,%s)"%tuple(IDLIST) print(sql) cursor.execute(sql) datalist=cursor.fetchall() except Exception as e: print(e.args) finally: conn.close() return datalist def save_data(dicts): now=datetime.datetime.now() conn=get_conn() data=((now,dicts["PAGE_CD"],"FB","FANS_NUM",dicts["FANS_NUM"],now),(now,dicts["PAGE_CD"],"FB","FOLLOW_NUM",dicts["FOLLOW_NUM"],now)) try: with conn.cursor() as cursor: sql="insert into sns_insight_log(LOG_DATE,BIZ_ID,MEDIA_TYPE,ITEM_NAME,DEC_VALUE,UPD_DATE) values(%s,%s,%s,%s,%s,%s)" cursor.executemany(sql,data) conn.commit() except: conn.rollback() finally: conn.close() if __name__=="__main__": print(get_idlist())