|
@@ -73,8 +73,9 @@ def get_rainfall(
|
|
|
twenty_four_hours_ago = now - timedelta(hours=num+1)
|
|
|
formatted_now = f"{now.strftime('%Y-%m-%d %H')}:00:00"
|
|
|
formatted_twenty_four_hours_ago = f"{twenty_four_hours_ago.strftime('%Y-%m-%d %H')}:00:00"
|
|
|
- sql = text("""SELECT SUM(rainfall) as rainfall FROM `govdata_rain_data_info` where `code`=:code and create_time BETWEEN :formatted_twenty_four_hours_ago and :formatted_now""").bindparams(code=code,formatted_twenty_four_hours_ago=formatted_twenty_four_hours_ago,formatted_now=formatted_now)
|
|
|
+ sql = text("""SELECT SUM(rainfall) as rainfall FROM sharedb.`govdata_rain_data_info` where `code`=:code and create_time BETWEEN :formatted_twenty_four_hours_ago and :formatted_now""").bindparams(code=code,formatted_twenty_four_hours_ago=formatted_twenty_four_hours_ago,formatted_now=formatted_now)
|
|
|
# 执行查询
|
|
|
+ # print(sql,formatted_now,formatted_twenty_four_hours_ago)
|
|
|
result = db.execute(sql).fetchone()
|
|
|
|
|
|
# 处理结果
|
|
@@ -86,4 +87,18 @@ def get_rainfall(
|
|
|
# for i in rainfulldata:
|
|
|
# value += i['F3070220000034_000018005']
|
|
|
#
|
|
|
- # return value
|
|
|
+ # return value
|
|
|
+
|
|
|
+def get_weather_warning(area_name : str,db: Session = Depends(get_db)):
|
|
|
+ area_name= area_name.replace('区','').replace('市','').replace('技术开发区','').replace('新区','')
|
|
|
+ sql = text(
|
|
|
+ """SELECT CONCAT(`type`,`state`) as `weather_warning_type`,levelnum as `weather_warninglevel` FROM sharedb.weather_latest_warnings where county = :county or county='茂名' ORDER BY `levelnum` desc LIMIT 1""").bindparams(
|
|
|
+ county=area_name)
|
|
|
+ # 执行查询
|
|
|
+ # print(sql,formatted_now,formatted_twenty_four_hours_ago)
|
|
|
+ result = db.execute(sql).fetchone()
|
|
|
+ # 处理结果
|
|
|
+ if result:
|
|
|
+ return dict(result)['weather_warning_type'],dict(result)['weather_warninglevel']
|
|
|
+ else:
|
|
|
+ return '-','-'
|