def gen_push_msg(self,sql_str,data): repo = WeixinDB() count = 0 create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') with repo: for msg in data: try: repo.execute_insert(sql_str,(msg.title,create_time,msg.content,msg.reason,msg.sort_id)) count = count + 1 except Exception, e: print e print ' at %s' % (create_time)
def pushMsg(self,data): repo = WeixinDB() count = 0 create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') with repo: for msg in data: try: sql = 'insert into approve_metadata (title,create_time,content,reason,sort_id) values (%s,%s,%s,%s,%s)' repo.execute_insert(sql,(msg.title,create_time,msg.content,'None',1)) count = count + 1 except Exception, e: print e print ' at %s' % (create_time)
def pushNews(self,data): repo = WeixinDB() with repo: start = time.localtime(time.time()) create_time = datetime.datetime(*start[:6]) for news in data: try: sql = 'insert into signature_news (title,create_time) values(%s,%s)' repo.execute_insert(sql,(news.title,create_time)) news_id = repo.last_record() for article in news.articles: sql = 'insert into signature_article (news_id,title,description,pic,url) values (%d,"%s","%s","%s","%s")' % (news_id, article.title,article.description,article.imageurl,article.url) repo.execute_insert(sql) except Exception, e: print e print ' at %s' % (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) return False else: return True