|
|
@@ -56,32 +56,24 @@ class GetWeather(APIView):
|
|
|
conn = sqlite3.connect(db)
|
|
|
cursor = conn.cursor()
|
|
|
table = "day_data" if day_type == "1" else "serven_day_data"
|
|
|
- sql = """
|
|
|
- select content from ? where province= ? and city = ? and district = ?
|
|
|
- """
|
|
|
- cursor.execute(sql, (table, province, city, district, ))
|
|
|
+ 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 = """
|
|
|
- select content from ? where province= ? and city = ?
|
|
|
- """
|
|
|
- cursor.execute(sql, (table, province, city, ))
|
|
|
+ sql = f"select content from {table} where province= '{province}' and city = '{city}'"
|
|
|
+ cursor.execute(sql)
|
|
|
result = cursor.fetchone()
|
|
|
if not result:
|
|
|
# 省正确
|
|
|
- sql = """
|
|
|
- select id from district where city = ?
|
|
|
- """
|
|
|
- cursor.execute(sql, (province,))
|
|
|
- provincd_id = cursor.fetchone()
|
|
|
- day_data_id = f"{provincd_id}0100000000"
|
|
|
- sql = """
|
|
|
- select content from ? where id = ?
|
|
|
- """
|
|
|
- cursor.execute(sql, (table, day_data_id, ))
|
|
|
+ sql = f"select content from {table} where province = '{province}'"
|
|
|
+ cursor.execute(sql)
|
|
|
result = cursor.fetchone()
|
|
|
- return Response({"content": result})
|
|
|
+ if result:
|
|
|
+ return Response({"content": result[0], "msg": "success", "code": 200})
|
|
|
+ else:
|
|
|
+ return Response({"content": "", "msg": "success", "code": 500})
|
|
|
except Exception as e:
|
|
|
logging.info(e)
|
|
|
return Response({"msg": "请联系管理员", "code": "50001"})
|