def gen_query_number(self,sql_str): result = 0 create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') repo = WeixinDB() with repo: try: query_tuple = repo.execute_query(sql_str) except Exception, e: print e print 'at %s ' % (create_time) else:
def gen_query_tuple(self,sql_str,*param): count = 0 result = list() create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') repo = WeixinDB() with repo: try: query_tuple = repo.execute_query(sql_str,param[0]) except Exception, e: print e print ' at %s' % (create_time) else:
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 msgSortMark(self,ids,sort_id): repo = WeixinDB() create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') count = 0 with repo: for msg_id in ids: try: sql_str = 'update approve_metadata set sort_id = %d where id = %d ' % (sort_id,msg_id) repo.execute_query(sql_str) 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 gen_delete_msg(self,sql_str,ids): action_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') repo = WeixinDB() count = 0 with repo: for msg_id in ids: try: if repo.execute_delete(sql_str,(int(msg_id))): count = count + 1 except Exception, e: print e print ' at %s' % (action_time) print 'delete %d messages at %s from WeixinDB' %(count,action_time) if count == len(ids): return True else: return False
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