예제 #1
0
 def run(self):
     reload(sys)
     sys.setdefaultencoding('utf-8')
     while True:
         # 判断是否需要获取关键字
         log.write_log(
             "[%d] Current number of keywords." % (self.data.qsize()),
             'info')
         if self.data.qsize() == 0:
             # 连接mysql数据库
             try:
                 self.mp = mysqlPal()
             except Exception, e:
                 s = sys.exc_info()
                 log.write_log(
                     "[baidu.py line:%d] Connect to the mysql database failed."
                     % (s[2].tb_lineno))
                 sys.exit()
             # 获取关键词
             criteria = {}
             keywordData = self.mp.find('news_keyword', criteria)
             for data in keywordData:
                 if data['name']:
                     self.data.put((data['name'].strip()))
                 if data['short_name']:
                     self.data.put((data['short_name'].strip()))
         else:
             time.sleep(10)
예제 #2
0
 def __init__(self, log):
     # 连接mysql数据库
     try:
         self.mp = mysqlPal()
     except Exception, e:
         s=sys.exc_info()
         log.write_log("[baidu.py line:%d] Connect to the mysql database failed."%(s[2].tb_lineno))
         sys.exit()