slight code cleanup, add windchill calculation
This commit is contained in:
		
							parent
							
								
									40c7603eac
								
							
						
					
					
						commit
						a8562f71a0
					
				| @ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License | ||||
| along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| import re | ||||
| 
 | ||||
| from extlib import irclib | ||||
| from extlib import pywapi | ||||
| 
 | ||||
| @ -34,7 +36,26 @@ class Weather(Module): | ||||
|         if whats[0] == "weather" and len(whats) >= 2: | ||||
|             try: | ||||
|                 google_weather = pywapi.get_weather_from_google(''.join(whats[1:])) | ||||
|                 weatherstr = "Current weather for " + google_weather['forecast_information']['city'].encode('utf-8') + ": " + google_weather['current_conditions']['condition'].encode('utf-8') + ". " + google_weather['current_conditions']['temp_f'].encode('utf-8') + "°F (" + google_weather['current_conditions']['temp_c'].encode('utf-8') + "°C), " + google_weather['current_conditions']['wind_condition'].encode('utf-8') + ", " + google_weather['current_conditions']['humidity'].encode('utf-8') + "." | ||||
|                 city = google_weather['forecast_information']['city'].encode('utf-8') | ||||
|                 condition = google_weather['current_conditions']['condition'].encode('utf-8') | ||||
|                 temp_f = google_weather['current_conditions']['temp_f'].encode('utf-8') | ||||
|                 temp_c = google_weather['current_conditions']['temp_c'].encode('utf-8') | ||||
|                 wind = google_weather['current_conditions']['wind_condition'].encode('utf-8') | ||||
|                 humidity = google_weather['current_conditions']['humidity'].encode('utf-8') | ||||
| 
 | ||||
|                 wind_speed_regex = re.compile("Wind: [NSEW]+ at ([0-9]+) mph") | ||||
|                 matches = wind_speed_regex.search(wind) | ||||
| 
 | ||||
|                 if matches is not None and float(temp_f) < 50.0: | ||||
|                     wind_speed = matches.group(1) | ||||
|                     windchill = 35.74 + (0.6215 * float(temp_f)) - (35.75 * float(wind_speed)**0.16) + (0.4275 * float(temp_f) * float(wind_speed)**0.16) | ||||
|                 else: | ||||
|                     windchill = "" | ||||
| 
 | ||||
|                 weatherstr = "Current weather for " + city + ": " + condition + ". " + temp_f + "°F (" + temp_c + "°C), " + wind + ", " + humidity | ||||
|                 if windchill is not "": | ||||
|                     weatherstr += ", Wind chill: " + str(round(windchill, 2)) + "°F" | ||||
|                 windchill += "." | ||||
| 
 | ||||
|                 for city in google_weather['forecasts']: | ||||
|                     weatherstr += " " + city['day_of_week'].encode('utf-8') + ": " + city['condition'].encode('utf-8') + ". High " + city['high'].encode('utf-8') + "°F, Low " + city['low'].encode('utf-8') + "°F." | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user