Weather module: new nemubot version fix

This commit is contained in:
nemunaire 2014-10-21 20:55:39 +02:00
parent fe709e630f
commit 67f6d49fb8

View File

@ -84,21 +84,20 @@ def format_timestamp(timestamp, tzname, tzoffset, format="%c"):
def treat_coord(msg): def treat_coord(msg):
if len(msg.cmds) > 1: if len(msg.args) > 0:
# catch dans X[jh]$ # catch dans X[jh]$
if len(msg.cmds) > 3 and msg.cmds[len(msg.cmds) - 2] == "dans" or msg.cmds[len(msg.cmds) - 2] == "in" or msg.cmds[len(msg.cmds) - 2] == "next": if len(msg.args) > 2 and (msg.args[-2] == "dans" or msg.args[-2] == "in" or msg.args[-2] == "next"):
specific = msg.cmds[len(msg.cmds) - 1] specific = msg.args[-1]
msg.cmds = msg.cmds[:len(msg.cmds) - 2] city = " ".join(msg.args[:-2]).lower()
else: else:
specific = None specific = None
city = " ".join(msg.args).lower()
j = " ".join(msg.cmds[1:]).lower() if len(msg.args) == 2:
coords = msg.args
if len(msg.cmds) == 3:
coords = msg.cmds[1:3]
else: else:
coords = msg.cmds[1].split(",") coords = msg.args[0].split(",")
try: try:
if len(coords) == 2 and str(float(coords[0])) == coords[0] and str(float(coords[1])) == coords[1]: if len(coords) == 2 and str(float(coords[0])) == coords[0] and str(float(coords[1])) == coords[1]:
@ -106,21 +105,21 @@ def treat_coord(msg):
except ValueError: except ValueError:
pass pass
if j in DATAS.index: if city in DATAS.index:
coords = list() coords = list()
coords.append(DATAS.index[j]["lat"]) coords.append(DATAS.index[city]["lat"])
coords.append(DATAS.index[j]["long"]) coords.append(DATAS.index[city]["long"])
return j, coords, specific return city, coords, specific
else: else:
geocode = [x for x in mapquest.geocode(j)] geocode = [x for x in mapquest.geocode(city)]
if len(geocode): if len(geocode):
coords = list() coords = list()
coords.append(geocode[0]["latLng"]["lat"]) coords.append(geocode[0]["latLng"]["lat"])
coords.append(geocode[0]["latLng"]["lng"]) coords.append(geocode[0]["latLng"]["lng"])
return mapquest.where(geocode[0]), coords, specific return mapquest.where(geocode[0]), coords, specific
raise IRCException("Je ne sais pas où se trouve %s." % " ".join(msg.cmds[1:])) raise IRCException("Je ne sais pas où se trouve %s." % city)
else: else:
raise IRCException("indique-moi un nom de ville ou des coordonnées.") raise IRCException("indique-moi un nom de ville ou des coordonnées.")
@ -138,15 +137,15 @@ def get_json_weather(coords):
def cmd_coordinates(msg): def cmd_coordinates(msg):
if len(msg.cmds) <= 1: if len(msg.args) < 1:
raise IRCException("indique-moi un nom de ville.") raise IRCException("indique-moi un nom de ville.")
j = msg.cmds[1].lower() j = msg.args[0].lower()
if j not in DATAS.index: if j not in DATAS.index:
raise IRCException("%s n'est pas une ville connue" % msg.cmds[1]) raise IRCException("%s n'est pas une ville connue" % msg.args[0])
coords = DATAS.index[j] coords = DATAS.index[j]
return Response("Les coordonnées de %s sont %s,%s" % (msg.cmds[1], coords["lat"], coords["long"]), channel=msg.channel) return Response("Les coordonnées de %s sont %s,%s" % (msg.args[0], coords["lat"], coords["long"]), channel=msg.channel)
def cmd_alert(msg): def cmd_alert(msg):
loc, coords, specific = treat_coord(msg) loc, coords, specific = treat_coord(msg)