User Tools

Site Tools


weatherbot

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
weatherbot [2014/08/30 10:40]
sekula
weatherbot [2014/08/30 23:23] (current)
sekula [Talking to WeatherBot]
Line 45: Line 45:
 import subprocess ​ import subprocess ​
 import os import os
 +import unicodedata
  
 from datetime import datetime from datetime import datetime
Line 122: Line 123:
 def CelsiusToFarenheit(temp_celsius):​ def CelsiusToFarenheit(temp_celsius):​
     return temp_celsius*1.8 + 32.0     return temp_celsius*1.8 + 32.0
 +
 +def FarenheitToCelsius(temp_farenheit):​
 +    return (temp_farenheit - 32.0)/1.8
  
 def KPHToMPH(speed_kph):​ def KPHToMPH(speed_kph):​
Line 135: Line 139:
     wind_speed_kmh = weather_data['​wind'​]['​speed'​]     wind_speed_kmh = weather_data['​wind'​]['​speed'​]
     wind_speed_mph = KPHToMPH(wind_speed_kmh)     wind_speed_mph = KPHToMPH(wind_speed_kmh)
 +    ​
 +    heat_index_farenheit = -42.379 + 2.04901523*temp_farenheit + 10.14333127*humidity - .22475541*temp_farenheit*humidity - .00683783*temp_farenheit*temp_farenheit - .05481717*humidity*humidity + .00122874*temp_farenheit*temp_farenheit*humidity + .00085282*temp_farenheit*humidity*humidity - .00000199*temp_farenheit*temp_farenheit*humidity*humidity
 +    heat_index_celsius = FarenheitToCelsius(heat_index_farenheit)
     ​     ​
     response = ""​     response = ""​
Line 143: Line 150:
     response += "<​li>​ Temperature:​ %0.1fC (%0.1fF) </​li>​\n"​ % (temp_celsius,​ temp_farenheit)     response += "<​li>​ Temperature:​ %0.1fC (%0.1fF) </​li>​\n"​ % (temp_celsius,​ temp_farenheit)
     response += "<​li>​ Humidity: %0.1f%% </li> \n" % (humidity)     response += "<​li>​ Humidity: %0.1f%% </li> \n" % (humidity)
 +    response += "<​li>​ Heat Index: %0.1fC (%0.1fF) </​li>​\n"​ % (heat_index_celsius,​heat_index_farenheit) ​   ​
     response += "<​li>​ Wind Speed: %.1fkm/h (%.1fmph) </​li>​\n"​ % (wind_speed_kmh,​wind_speed_mph)     response += "<​li>​ Wind Speed: %.1fkm/h (%.1fmph) </​li>​\n"​ % (wind_speed_kmh,​wind_speed_mph)
     response += "<​li>​ Conditions: %s - %s</​li>​ \n" % (weather_data['​weather'​][0]['​main'​],​ weather_data['​weather'​][0]['​description'​])     response += "<​li>​ Conditions: %s - %s</​li>​ \n" % (weather_data['​weather'​][0]['​main'​],​ weather_data['​weather'​][0]['​description'​])
Line 276: Line 284:
                             pass                             pass
                         ​                         ​
-                        print "%s sent a weather request for the %s for %s, which I will now process..."​ % (activity.obj.author, query_type, cityrequest)+                        ​author = ""​ 
 +                        if type(activity.obj.author) == Person: 
 +                            author = activity.obj.author.display_name 
 +                        elif type(activity.obj.author) == unicode: 
 +                            author = unicodedata.normalize('​NFKD',​ activity.obj.author).encode('​ascii','​ignore'​) 
 +                        else: 
 +                            author = activity.obj.author 
 +                            pass 
 +                                                 
 +                        ​print "%s sent a weather request for the %s for %s, which I will now process..."​ % (author, query_type, cityrequest)
                         ​                         ​
                         # clean up poor formatting in content                         # clean up poor formatting in content
Line 388: Line 405:
 ===== Talking to WeatherBot ===== ===== Talking to WeatherBot =====
  
-WeatherBot (e,g[[https://​hub.polari.us/​weather]]) can now take various request forms. Sending these:+WeatherBot (e.g[[https://​hub.polari.us/​weather]]) can now take various request forms. Sending these:
  
 <​code>​ <​code>​
 New York,NY,US New York,NY,US
 or or
-New York,US+Stockholm,SE
 </​code>​ </​code>​
  
Line 418: Line 435:
  
 will return a table of forecast data for the city in question, going out 3 days. This is just a first attempt to do simple request processing based on language, and, yes, it's only in English for now. But now you can at least get a forecast! will return a table of forecast data for the city in question, going out 3 days. This is just a first attempt to do simple request processing based on language, and, yes, it's only in English for now. But now you can at least get a forecast!
 +
 +{{ :​weatherbot_forecast.png?​direct&​300 |}}
  
weatherbot.1409409601.txt.gz · Last modified: 2014/08/30 10:40 by sekula