@@ -29,33 +29,33 @@ def get_weather(key):
29
29
payload = {'location' : 'beijing' , 'key' : key }
30
30
r = requests .get ('https://free-api.heweather.com/s6/weather/forecast' , params = payload )
31
31
today_forecast = r .json ()['HeWeather6' ][0 ]['daily_forecast' ][0 ]
32
- tomorow_forecast = r .json ()['HeWeather6' ][0 ]['daily_forecast' ][1 ]
32
+ tomorrow_forecast = r .json ()['HeWeather6' ][0 ]['daily_forecast' ][1 ]
33
33
today_code_n = today_forecast ['cond_code_n' ]
34
- tomorow_code_d = tomorow_forecast ['cond_code_d' ]
34
+ tomorrow_code_d = tomorrow_forecast ['cond_code_d' ]
35
35
print ('today_code_n = ' + today_code_n )
36
- print ('tomorow_code_d = ' + tomorow_code_d )
36
+ print ('tomorrow_code_d = ' + tomorrow_code_d )
37
37
weather_content = air_content = temprature_content = ''
38
38
today_txt_n = today_forecast ['cond_txt_n' ] # 今天夜间天气状况文字
39
- tomorow_txt_d = tomorow_forecast ['cond_txt_d' ] # 明天白天天气状况文字
39
+ tomorrow_txt_d = tomorrow_forecast ['cond_txt_d' ] # 明天白天天气状况文字
40
40
today_tmp_max = today_forecast ['tmp_max' ] # 今天最高气温
41
41
today_tmp_min = today_forecast ['tmp_min' ] # 今天最低气温
42
- tomorow_tmp_max = tomorow_forecast ['tmp_max' ] # 明天最高气温
43
- tomorow_tmp_min = tomorow_forecast ['tmp_min' ] # 明天最低气温
44
- if (int (today_code_n ) > 299 and int (today_code_n ) < 500 ) or (int (tomorow_code_d ) > 299 and int (tomorow_code_d ) < 500 ):
45
- weather_content = '降水注意:' + '\n ' + '今天夜间天气为【' + today_txt_n + '】,最高气温:' + str (today_tmp_max ) + '°C,最低气温:' + str (today_tmp_min ) + '°C;' + '\n ' + '明天白天天气为【' + tomorow_txt_d + '】,最高气温' + str (
46
- tomorow_tmp_max ) + '°C,最低气温' + str (tomorow_tmp_min ) + '°C。' + '\n '
42
+ tomorrow_tmp_max = tomorrow_forecast ['tmp_max' ] # 明天最高气温
43
+ tomorrow_tmp_min = tomorrow_forecast ['tmp_min' ] # 明天最低气温
44
+ if (int (today_code_n ) > 299 and int (today_code_n ) < 500 ) or (int (tomorrow_code_d ) > 299 and int (tomorrow_code_d ) < 500 ):
45
+ weather_content = '降水注意:' + '\n ' + '今天夜间天气为【' + today_txt_n + '】,最高气温:' + str (today_tmp_max ) + '°C,最低气温:' + str (today_tmp_min ) + '°C;' + '\n ' + '明天白天天气为【' + tomorrow_txt_d + '】,最高气温' + str (
46
+ tomorrow_tmp_max ) + '°C,最低气温' + str (tomorrow_tmp_min ) + '°C。' + '\n '
47
47
print (weather_content )
48
- if (int (today_code_n ) > 501 and int (today_code_n ) < 900 ) or (int (tomorow_code_d ) > 501 and int (tomorow_code_d ) < 900 ):
49
- air_content = '空气质量注意:' + '\n ' + '今天夜间天气为【' + today_txt_n + '】;' + '\n ' + '明天白天天气为【' + tomorow_txt_d + '】' + '\n '
48
+ if (int (today_code_n ) > 501 and int (today_code_n ) < 900 ) or (int (tomorrow_code_d ) > 501 and int (tomorrow_code_d ) < 900 ):
49
+ air_content = '空气质量注意:' + '\n ' + '今天夜间天气为【' + today_txt_n + '】;' + '\n ' + '明天白天天气为【' + tomorrow_txt_d + '】' + '\n '
50
50
current_month = time .strftime ("%m" , time .localtime ())
51
51
if (int (current_month ) > 0 and int (current_month ) < 5 ) or (int (current_month ) > 8 and int (current_month ) <= 12 ):
52
52
print ('当前是%s月%s日' % (current_month , time .strftime ("%d" , time .localtime ())))
53
- if (int (tomorow_tmp_min ) - int (today_tmp_min )) <= - 5 :
54
- temprature_content = '温度注意:明日最低气温为' + tomorow_tmp_min + '°C!' + '\n '
53
+ if (int (tomorrow_tmp_min ) - int (today_tmp_min )) <= - 5 :
54
+ temprature_content = '温度注意:明日最低气温为' + tomorrow_tmp_min + '°C!' + '\n '
55
55
if int (current_month ) > 4 and int (current_month ) < 9 :
56
56
print ('当前是%s月%s日' % (current_month , time .strftime ("%d" , time .localtime ())))
57
- if ((int (tomorow_tmp_max ) - int (today_tmp_max )) >= 5 ) or (int (tomorow_tmp_max ) >= 30 ):
58
- temprature_content = '温度注意:明日最高气温为' + tomorow_tmp_max + '°C!' + '\n '
57
+ if ((int (tomorrow_tmp_max ) - int (today_tmp_max )) >= 5 ) or (int (tomorrow_tmp_max ) >= 30 ):
58
+ temprature_content = '温度注意:明日最高气温为' + tomorrow_tmp_max + '°C!' + '\n '
59
59
60
60
return weather_content + air_content + temprature_content
61
61
0 commit comments