async def record_by_province(self, province): rows = SariRecord.by_province(province) result = parse_single_data(to_json(rows)) return { "status": True, "code": StatusCode.success.value, "msg": "获取成功", "data": result }
async def records(self, location=None): if location: rows = SariRecord.by_country() else: rows = SariRecord.all() need_parse = dict() result = list() for row in to_json(rows): if not need_parse.get(row.get('provinceName')): need_parse.setdefault(row.get('provinceName'), [row]) else: need_parse[row.get('provinceName')].append(row) for v in need_parse.values(): result.append(parse_single_data(v, location)) return { "status": True, "code": StatusCode.success.value, "msg": "获取成功", "data": result }
def _save_data(self, records): for record in records: self.log.debug( f"{record.get('provinceName')} - {record.get('cityName')} saving" ) SariRecord.update_and_insert(**record)