|
|
|
@ -2,6 +2,7 @@ import time
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import meteofrance_api as mf
|
|
|
|
|
|
|
|
|
|
DEPENDENCIES_FOUND = True
|
|
|
|
|
except ImportError:
|
|
|
|
|
DEPENDENCIES_FOUND = False
|
|
|
|
@ -12,9 +13,14 @@ from edmond.plugin import Plugin
|
|
|
|
|
class MeteoFrancePlugin(Plugin):
|
|
|
|
|
|
|
|
|
|
REQUIRED_CONFIGS = [
|
|
|
|
|
"commands", "result_message", "nearest_message", "temp_format",
|
|
|
|
|
"rain_chance_format", "all_rain_format", "today_message",
|
|
|
|
|
"minmax_temp_format"
|
|
|
|
|
"commands",
|
|
|
|
|
"result_message",
|
|
|
|
|
"nearest_message",
|
|
|
|
|
"temp_format",
|
|
|
|
|
"rain_chance_format",
|
|
|
|
|
"all_rain_format",
|
|
|
|
|
"today_message",
|
|
|
|
|
"minmax_temp_format",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
@ -54,7 +60,8 @@ class MeteoFrancePlugin(Plugin):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
result = self.config["result_message"].format(
|
|
|
|
|
nearest_s=nearest_s, today_s=today_s)
|
|
|
|
|
nearest_s=nearest_s, today_s=today_s
|
|
|
|
|
)
|
|
|
|
|
self.bot.say(event.target, result)
|
|
|
|
|
|
|
|
|
|
def format_nearest_forecast(self, nearest, place):
|
|
|
|
@ -65,43 +72,52 @@ class MeteoFrancePlugin(Plugin):
|
|
|
|
|
wind = self.format_wind(nearest["wind"])
|
|
|
|
|
rain = self.format_rain_perc(nearest["rain"])
|
|
|
|
|
return self.config["nearest_message"].format(
|
|
|
|
|
city=city, hour=hour, weather=weather, temp=temp, wind=wind,
|
|
|
|
|
rain=rain
|
|
|
|
|
city=city,
|
|
|
|
|
hour=hour,
|
|
|
|
|
weather=weather,
|
|
|
|
|
temp=temp,
|
|
|
|
|
wind=wind,
|
|
|
|
|
rain=rain,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def format_temperature(self, temperature):
|
|
|
|
|
temp_c = temperature.get("value", "?")
|
|
|
|
|
temp_wc = temperature.get("windchill", "?")
|
|
|
|
|
return self.config["temp_format"].format(
|
|
|
|
|
temp_c=temp_c, temp_wc=temp_wc)
|
|
|
|
|
temp_c=temp_c, temp_wc=temp_wc
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def format_rain_perc(self, rain_percs):
|
|
|
|
|
perc_fmt = self.config["rain_chance_format"]
|
|
|
|
|
all_percs = ', '.join(
|
|
|
|
|
perc_fmt.format(p=p, h=h)
|
|
|
|
|
for h, p in rain_percs.items()
|
|
|
|
|
all_percs = ", ".join(
|
|
|
|
|
perc_fmt.format(p=p, h=h) for h, p in rain_percs.items()
|
|
|
|
|
)
|
|
|
|
|
return self.config["all_rain_format"].format(all_percs=all_percs)
|
|
|
|
|
|
|
|
|
|
def format_wind(self, wind):
|
|
|
|
|
speed = wind.get('speed')
|
|
|
|
|
direction = wind.get('icon')
|
|
|
|
|
speed = wind.get("speed")
|
|
|
|
|
direction = wind.get("icon")
|
|
|
|
|
if direction == "Variable":
|
|
|
|
|
direction = self.config["unknown_direction"]
|
|
|
|
|
return self.config["wind_format"].format(
|
|
|
|
|
speed=speed, direction=direction)
|
|
|
|
|
speed=speed, direction=direction
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def format_today_forecast(self, today_f):
|
|
|
|
|
temp = today_f['T']
|
|
|
|
|
temp = today_f["T"]
|
|
|
|
|
temp_minmax = self.config["minmax_temp_format"].format(
|
|
|
|
|
t_max=temp["max"], t_min=temp["min"])
|
|
|
|
|
rain = self.format_rain_perc(today_f['precipitation'])
|
|
|
|
|
sunset = format_ts_hour(today_f['sun']['set'])
|
|
|
|
|
t_max=temp["max"], t_min=temp["min"]
|
|
|
|
|
)
|
|
|
|
|
rain = self.format_rain_perc(today_f["precipitation"])
|
|
|
|
|
sunset = format_ts_hour(today_f["sun"]["set"])
|
|
|
|
|
return self.config["today_message"].format(
|
|
|
|
|
temp_minmax=temp_minmax, rain=rain, sunset=sunset)
|
|
|
|
|
temp_minmax=temp_minmax, rain=rain, sunset=sunset
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_ts_hour(timestamp):
|
|
|
|
|
return time.strftime("%H:%M", time.localtime(timestamp))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_weather(weather):
|
|
|
|
|
return weather.get("desc", "?").lower()
|
|
|
|
|