def treat_coord(msg): if len(msg.args) > 0: # catch dans X[jh]$ if len(msg.args) > 2 and (msg.args[-2] == "dans" or msg.args[-2] == "in" or msg.args[-2] == "next"): specific = msg.args[-1] city = " ".join(msg.args[:-2]).lower() else: specific = None city = " ".join(msg.args).lower() if len(msg.args) == 2: coords = msg.args else: coords = msg.args[0].split(",") try: if len(coords) == 2 and str(float(coords[0])) == coords[0] and str(float(coords[1])) == coords[1]: return coords, specific except ValueError: pass if city in context.data.index: coords = list() coords.append(context.data.index[city]["lat"]) coords.append(context.data.index[city]["long"]) return city, coords, specific else: geocode = [x for x in mapquest.geocode(city)] if len(geocode): coords = list() coords.append(geocode[0]["latLng"]["lat"]) coords.append(geocode[0]["latLng"]["lng"]) return mapquest.where(geocode[0]), coords, specific raise IMException("Je ne sais pas où se trouve %s." % city) else: raise IMException("indique-moi un nom de ville ou des coordonnées.")
def cmd_flight(msg): if not len(msg.args): raise IMException("please indicate a flight") res = Response(channel=msg.channel, nick=msg.nick, nomore="No more flights", count=" (%s more flights)") for param in msg.args: for flight in virtual_radar(param): if 'Lat' in flight and 'Long' in flight: loc = None for location in mapquest.geocode('{Lat},{Long}'.format(**flight)): loc = location break if loc: res.append_message('\x02{0}\x0F: Position: \x02{1}\x0F, {2}'.format(flight['Call'], \ mapquest.where(loc), \ ', '.join(filter(None, flight_info(flight))))) continue res.append_message('\x02{0}\x0F: {1}'.format(flight['Call'], \ ', '.join(filter(None, flight_info(flight))))) return res