def batch_get_recommend_cuid_info(self,servicekey,secretkey,subservice,srcType): while 1: try: get_file('/home/map/importer/TgBrand0_import/status.txt',self.data_directory+"status.txt") status0=get_file_lines(self.data_directory+"status.txt")[0].strip() get_file('/home/map/importer/TgBrand1_import/status.txt',self.data_directory+"status.txt") status1=get_file_lines(self.data_directory+"status.txt")[0].strip() print status0,status1 if(status0 == 'checking' and status1 == 'checking'): print(u"数据导入redis ready,开始查询系统推荐信息...") break else: print(u"数据导入redis还未ready,60s之后继续监测...") time.sleep(60) except Exception as e: print(str(e)) for i,sample in enumerate(self.sample_list): self.sample_list[i]=self.sample_list[i].strip() fp=open(self.data_directory+self.event_day+self.recommend_info_filepath,"w") for cuid in self.sample_list: print cuid ret=str(queryUserPreference(servicekey,secretkey,subservice,cuid,srcType)) ret=cuid+"\t"+ret self.recommend_info_list.append(ret) fp.write(ret+"\n") fp.close()
#!/usr/bin/env python # -*- coding: utf-8 -*- from common.logLib import * from common.msgSend import * from common.queryUserPreference import * import time TM_INTERVAL = 60 Exception_INTERVAL = 3600 phonenum_list = ["18665817689", "18665910949", "18666662305", "13632979619"] msg_content = "userPreference:getResponse failed" cnt = 1 while 1: status = queryUserPreference() if status == 0 and cnt == 3: cnt = 0 time.sleep(TM_INTERVAL) elif status == -1 and cnt == 3: logging.error(msg_content + str(cnt) + " times") msgSend(phonenum_list, msg_content) cnt = 0 time.sleep(Exception_INTERVAL) elif status == -1 and cnt != 3: logging.error(msg_content + str(cnt) + " times") cnt += 1 time.sleep(TM_INTERVAL) else: time.sleep(TM_INTERVAL)