|
@@ -1,7 +1,7 @@
|
|
|
from rest_framework.views import APIView
|
|
from rest_framework.views import APIView
|
|
|
from rest_framework.response import Response
|
|
from rest_framework.response import Response
|
|
|
from django.contrib.auth import authenticate
|
|
from django.contrib.auth import authenticate
|
|
|
-from apps.Weather.models import DayData, ServerDayData
|
|
|
|
|
|
|
+from apps.Weather.models import DayData, ServerDayData, AddressInfo, HistoryData
|
|
|
from apps.UserApp.models import MyUser
|
|
from apps.UserApp.models import MyUser
|
|
|
|
|
|
|
|
import logging
|
|
import logging
|
|
@@ -98,6 +98,42 @@ class GetWeather(APIView):
|
|
|
return Response({"msg": "请联系管理员", "code": "50001"})
|
|
return Response({"msg": "请联系管理员", "code": "50001"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def HistoryAPIView(APIView):
|
|
|
|
|
+
|
|
|
|
|
+ def post(self, request):
|
|
|
|
|
+ data = request.data
|
|
|
|
|
+ timestamp = data.get("timestamp")
|
|
|
|
|
+ province = data.get("province")
|
|
|
|
|
+ city = data.get("city")
|
|
|
|
|
+ district = data.get("district")
|
|
|
|
|
+ district = AddressInfo.objects.filter(province=province, city=city, district=district)
|
|
|
|
|
+ if district:
|
|
|
|
|
+ cityid = district.first().cityid
|
|
|
|
|
+ else:
|
|
|
|
|
+ msg = f"地区:{district} 取不到,使用 {province} {city} 取"
|
|
|
|
|
+ logging.warning(msg)
|
|
|
|
|
+ city = AddressInfo.objects.filter(province=province, city=city)
|
|
|
|
|
+ if city:
|
|
|
|
|
+ cityid = city.first().cityid
|
|
|
|
|
+ else:
|
|
|
|
|
+ return Response({"msg": "暂无数据", "code": 500})
|
|
|
|
|
+ # 去历史表中查询数据
|
|
|
|
|
+ try:
|
|
|
|
|
+ history_data = HistoryData.objects.get(cityid=cityid, timestamp=timestamp)
|
|
|
|
|
+ content = history_data.content
|
|
|
|
|
+ low_heigh = json.loads(content)
|
|
|
|
|
+ return Response(
|
|
|
|
|
+ {
|
|
|
|
|
+ "data": [low_heigh["yWendu"], low_heigh["bWendu"]],
|
|
|
|
|
+ "province": province,
|
|
|
|
|
+ "city": city,
|
|
|
|
|
+ "district": district
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ return Response({"msg": "暂无指定城市数据", "code": 500})
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class TestAPI(APIView):
|
|
class TestAPI(APIView):
|
|
|
|
|
|
|
|
def post(self, request):
|
|
def post(self, request):
|