def main(self): """ 主函数 :return: """ try: data = self.get_raw_real_time_info() now_data = self.change_raw_data_format(data) # 加载上一次最新的数据 last_data = load_last_info(self.re) if not last_data: save_json_info(self.re, STATE_NCOV_INFO, now_data) last_data = now_data update_city = self.parse_increase_info(now_data, last_data) # 如果数据有更新,则保存新数据和更新的数据 if len(update_city) > 0: self.re.set(SHOULD_UPDATE, 1) save_json_info(self.re, STATE_NCOV_INFO, now_data) save_json_info_as_key(self.re, UPDATE_CITY, update_city) self.log.logging.info("set update city {}".format( json.dumps(update_city))) else: # self.re.set(SHOULD_UPDATE, 0) self.log.logging.info("no update city") except BaseException as e: self.log.logging.exception(e)
def get_ncvo_info_with_city(conn, citys, group=False): """ 根据传入的城市列表获取疫情信息 :param conn: redis连接 :param citys: :return: """ try: last = load_last_info(conn) ncov = [] if not last: return NO_NCOV_INFO.format(", ".join(citys)) for city in citys: if city in last: info = last[city] ncov.append( FIRST_NCOV_INFO.format(info['city'], info['confirm'], info['dead'], info['heal'])) if group: today_info = get_today_push_info(info) if len(today_info) > 0: ncov.append(today_info) else: ncov.append(NO_NCOV_INFO.format(city)) return ";".join(ncov) except BaseException as e: ls.logging.exception(e) return NO_NCOV_INFO.format(",".join(citys))
def main(self): """ 主函数 :return: """ try: data = self.get_raw_real_time_info() chinaTotal = data['chinaTotal'] # 腾讯areaTree中的全国数据与chinaTotal不一致,以chinaTotal为准 now_data = self.change_raw_data_format_new(data['areaTree']) now_data['全国']['confirm'] = int(chinaTotal['confirm']) now_data['全国']['suspect'] = int(chinaTotal['suspect']) now_data['全国']['dead'] = int(chinaTotal['dead']) now_data['全国']['heal'] = int(chinaTotal['heal']) # 保存所有的地区名 self.save_all_area(now_data) # 加载上一次最新的数据 last_data = load_last_info(self.re) if not last_data: save_json_info(self.re, STATE_NCOV_INFO, now_data) last_data = now_data update_city = self.parse_increase_info(now_data, last_data) if USE_REDIS: should_update = self.re.get(SHOULD_UPDATE) should_update = 0 if should_update == None else should_update else: should_update = self.sqlc.get_update_flag() # 如果数据有更新,则保存新数据和更新的数据 if len(update_city) > 0: save_json_info(self.re, STATE_NCOV_INFO, now_data) if should_update == 0: if USE_REDIS: self.re.set(SHOULD_UPDATE, 1) else: self.sqlc.do_update_flag(1) # 如果上一次的数据还没推出去,要先合并新增数据 elif should_update == 1: old_update_city = self.get_old_data_city() if old_update_city != None: update_city = self.merge_update_city( old_city_list=old_update_city, new_city_list=update_city) save_json_info_as_key(self.re, UPDATE_CITY, update_city) self.log.logging.info("set update city {}".format( json.dumps(update_city)[:20])) else: # self.re.set(SHOULD_UPDATE, 0) self.log.logging.info("no update city") except BaseException as e: self.log.logging.exception(e)
def get_ncvo_info_with_city(conn, citys): """ 根据传入的城市列表获取疫情信息 :param conn: redis连接 :param citys: :return: """ last = load_last_info(conn) ncov = [] for city in citys: if city in last: info = last[city] ncov.append( FIRST_NCOV_INFO.format(info['city'], info['confirm'], info['dead'], info['heal'])) else: ncov.append(NO_NCOV_INFO.format(city)) return ";".join(ncov)