Created
November 22, 2015 12:22
-
-
Save quantenProjects/9b9748a4aa6a00d04db2 to your computer and use it in GitHub Desktop.
Weather Plugin for Hangoutsbot. Usage /bot wetter Hamburg Weatherdata from OpenWeatherMap. API-Key: http://openweathermap.org/appid Hangoutsbot: https://github.com/hangoutsbot/hangoutsbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plugins | |
import pyowm | |
def _initialise(bot): | |
plugins.register_user_command(["wetter"]) | |
def wetter(bot, event, *args): | |
# own API-Key from OpenWeatherMap needed | |
owm = pyowm.OWM('apikey') | |
term = " ".join(args) | |
if not term: | |
return | |
try: | |
observation = owm.weather_at_place(term) | |
w = observation.get_weather() | |
weather = w.get_detailed_status() + "<br/>" | |
weather += str(w.get_temperature(unit='celsius')['temp']) + "°C " + str(w.get_humidity()) + "%<br/>" | |
weather += str(w.get_wind()['speed']) + " m/s " + wind_deg2txt(w.get_wind()['deg']) | |
html_text = "Wetter für: " + observation.get_location().get_name() + ", " + observation.get_location().get_country() + "<br/>" + weather | |
except: | |
html_text="Mein Fenster ist beschlagen, ich kann nicht nach dem Wetter schauen" + sys.exc_info()[0] | |
yield from bot.coro_send_message(event.conv, html_text) | |
def wind_deg2txt(deg): | |
wind_dir_name = ['N','NO','O','SO','S','SW','W','NW','N'] | |
wind_sections = 360 / 8 | |
offset = wind_sections / 2 | |
y = int( (deg + offset) / wind_sections ) | |
wind_dir_txt = wind_dir_name[y] | |
return(wind_dir_txt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment