|
@@ -51,6 +51,7 @@ class GetWeather(APIView):
|
|
|
try:
|
|
try:
|
|
|
db = "/data/weather/weather.db"
|
|
db = "/data/weather/weather.db"
|
|
|
data = request.data
|
|
data = request.data
|
|
|
|
|
+ cityid = data.get("cityid", "")
|
|
|
province = data.get("province")
|
|
province = data.get("province")
|
|
|
city = data.get("city")
|
|
city = data.get("city")
|
|
|
district = data.get("district")
|
|
district = data.get("district")
|
|
@@ -68,29 +69,40 @@ class GetWeather(APIView):
|
|
|
return Response({"msg":"认证失败", "code": 400})
|
|
return Response({"msg":"认证失败", "code": 400})
|
|
|
table = "day_data" if day_type == "1" else "serven_day_data"
|
|
table = "day_data" if day_type == "1" else "serven_day_data"
|
|
|
table = "day_data" if day_type == "1" else "server_day_data"
|
|
table = "day_data" if day_type == "1" else "server_day_data"
|
|
|
- sql = f"select content from {table} where province = '{province}' and city ='{city}' and district ='{district}'"
|
|
|
|
|
- cursor.execute(sql)
|
|
|
|
|
- result = cursor.fetchone()
|
|
|
|
|
- if not result:
|
|
|
|
|
- # 省市正确
|
|
|
|
|
- sql = f"select content from {table} where province= '{province}' and city = '{city}'"
|
|
|
|
|
|
|
+ if cityid:
|
|
|
|
|
+ sql = f"select content from {table} where cityid = '{cityid}'"
|
|
|
cursor.execute(sql)
|
|
cursor.execute(sql)
|
|
|
result = cursor.fetchone()
|
|
result = cursor.fetchone()
|
|
|
- if not result:
|
|
|
|
|
- # 省正确
|
|
|
|
|
- sql = f"select content from {table} where province = '{province}'"
|
|
|
|
|
- cursor.execute(sql)
|
|
|
|
|
- result = cursor.fetchone()
|
|
|
|
|
- if result:
|
|
|
|
|
- try:
|
|
|
|
|
|
|
+ if result:
|
|
|
temp = result[0].replace("'", '"')
|
|
temp = result[0].replace("'", '"')
|
|
|
result = json.loads(temp)
|
|
result = json.loads(temp)
|
|
|
return Response({"content": result, "msg": "success", "code": 200})
|
|
return Response({"content": result, "msg": "success", "code": 200})
|
|
|
- except Exception as e:
|
|
|
|
|
- logging.info(e)
|
|
|
|
|
- return Response({"msg": "请联系管理员", "code": "50001"})
|
|
|
|
|
|
|
+ else:
|
|
|
|
|
+ return Response({"msg": "请联系管理员排查", "code": 500})
|
|
|
else:
|
|
else:
|
|
|
- return Response({"content": "", "msg": "success", "code": 500})
|
|
|
|
|
|
|
+ sql = f"select content from {table} where province = '{province}' and city ='{city}' and district ='{district}'"
|
|
|
|
|
+ cursor.execute(sql)
|
|
|
|
|
+ result = cursor.fetchone()
|
|
|
|
|
+ if not result:
|
|
|
|
|
+ # 省市正确
|
|
|
|
|
+ sql = f"select content from {table} where province= '{province}' and city = '{city}'"
|
|
|
|
|
+ cursor.execute(sql)
|
|
|
|
|
+ result = cursor.fetchone()
|
|
|
|
|
+ if not result:
|
|
|
|
|
+ # 省正确
|
|
|
|
|
+ sql = f"select content from {table} where province = '{province}'"
|
|
|
|
|
+ cursor.execute(sql)
|
|
|
|
|
+ result = cursor.fetchone()
|
|
|
|
|
+ if result:
|
|
|
|
|
+ try:
|
|
|
|
|
+ temp = result[0].replace("'", '"')
|
|
|
|
|
+ result = json.loads(temp)
|
|
|
|
|
+ return Response({"content": result, "msg": "success", "code": 200})
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logging.info(e)
|
|
|
|
|
+ return Response({"msg": "请联系管理员", "code": "50001"})
|
|
|
|
|
+ else:
|
|
|
|
|
+ return Response({"content": "", "msg": "success", "code": 500})
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logging.info(e)
|
|
logging.info(e)
|
|
|
return Response({"msg": "请联系管理员", "code": "50001"})
|
|
return Response({"msg": "请联系管理员", "code": "50001"})
|