def schedule(self): if self.schedule_enable: now = datetime.now() print now if now.hour == self.set_time["hour"] and now.minute == self.set_time["minute"]: if not self.push_flag and self.image_exist: print "target time!" self.push_msg_to_target_contact(utils.get_image_path(), True) self.push_msg_to_target_group(utils.get_image_path(), True) # self.push_weather_information() self.push_flag = True else: self.push_flag = False
def main(): # 启动天气服务 print 'start' weather_service = WeatherService() weather_service.refresh() print 'weather_service init over' # 启动机器人 bot = WeatherBot() bot.set_weather_service(weather_service) print 'image create over' # 启动图片渲染服务 image_service = ImageService() image_service.generate_image(weather_service.get_publish_message(), utils.get_image_path(), bot.set_image_exist) # 启动定时服务 schedule_service = ScheduleService(weather_service, bot, image_service) schedule_service.start_service() print 'start schedule' bot.DEBUG = True bot.conf['qr'] = 'tty' bot.run()
def refresh_cache(self): print 'refresh weather service' self.weather_service.refresh() msg = self.weather_service.get_publish_message() self.image_service.generate_image(msg, utils.get_image_path(), self.refresh_over) self.schedule.enter(self.INTERVAL_WEATHER_REFRESH, 1, self.refresh_cache, ())
def push_weather_information(self): print '接受推送请求' if self.image_exist: weather_img = utils.get_image_path() #获取天气图片 else: weather_img = 'img/1.png' print '获取图片路径' self.push_msg_to_target_contact(weather_img, True) self.push_msg_to_target_group(weather_img, True) print '推送图片' has_txt = True # 存在第二条文本消息 weather_txt = "天气已推送~" if has_txt: self.push_msg_to_target_contact(weather_txt) self.push_msg_to_target_group(weather_txt) print '推送第二条消息'
def push_weather_information(self): # 调用weather_service接口获得天气信息 print '接受推送请求' if self.image_exist: weather_img = utils.get_image_path() else: weather_img = 'img/1.png' print '获取图片路径' self.push_msg_to_target_contact(weather_img, True) self.push_msg_to_target_group(weather_img, True) print '推送图片' has_txt = True # 存在第二条文本消息 weather_txt = "今天天气真好" if has_txt: self.push_msg_to_target_contact(weather_txt) self.push_msg_to_target_group(weather_txt) print '推送第二条消息'