RATP: clean and update module

This commit is contained in:
nemunaire 2014-09-19 01:42:37 +02:00
parent ae3c46e693
commit 880b2950d3

View File

@ -2,46 +2,39 @@
"""Informe les usagers des prochains passages des transports en communs de la RATP"""
import http.client
import re
from xml.dom.minidom import parseString
from .external.src import ratp
from hooks import hook
nemubotversion = 3.4
def load(context):
global DATAS
DATAS.setIndex("name", "station")
from .external.src import ratp
def help_full ():
return "!ratp transport line [station]: Donne des informations sur les prochains passages du transport en commun séléctionné à l'arrêt désiré. Si aucune station n'est précisée, les liste toutes."
def extractInformation(msg, transport, line, station=None):
if station is not None and station != "":
times = ratp.getNextStopsAtStation(transport, line, station)
if len(times) > 0:
(time, direction, stationname) = times[0]
return Response(message=["\x03\x02"+time+"\x03\x02 direction "+direction for time, direction, stationname in times], title="Prochains passages du %s ligne %s à l'arrêt %s" %
(transport, line, stationname), channel=msg.channel)
else:
raise IRCException("La station `%s' ne semble pas exister sur le %s ligne %s."
% (station, transport, line))
else:
stations = ratp.getAllStations(transport, line)
if len(stations) == 0:
raise IRCException("aucune station trouvée.")
return Response([s for s in stations], title="Stations", channel=msg.channel)
@hook("cmd_hook", "ratp")
def ask_ratp(msg):
"""Hook entry from !ratp"""
global DATAS
if len(msg.cmds) == 4:
return extractInformation(msg, msg.cmds[1], msg.cmds[2], msg.cmds[3])
transport = msg.cmds[1]
line = msg.cmds[2]
station = msg.cmds[3]
times = ratp.getNextStopsAtStation(transport, line, station)
if len(times) == 0:
raise IRCException("la station %s n'existe pas sur le %s ligne %s." % (station, transport, line))
(time, direction, stationname) = times[0]
return Response(message=["\x03\x02%s\x03\x02 direction %s" % (time, direction) for time, direction, stationname in times],
title="Prochains passages du %s ligne %s à l'arrêt %s" % (transport, line, stationname),
channel=msg.channel)
elif len(msg.cmds) == 3:
return extractInformation(msg, msg.cmds[1], msg.cmds[2])
stations = ratp.getAllStations(msg.cmds[1], msg.cmds[2])
if len(stations) == 0:
raise IRCException("aucune station trouvée.")
return Response([s for s in stations], title="Stations", channel=msg.channel)
else:
raise IRCException("Mauvais usage, merci de spécifier un type de transport et une ligne, ou de consulter l'aide du module.")
return False