Update nextstop module for v3.3

This commit is contained in:
Némunaire 2012-11-04 15:33:04 +01:00
parent c6d5d88723
commit 20f5c5f453

View File

@ -4,12 +4,9 @@ import http.client
import re import re
from xml.dom.minidom import parseString from xml.dom.minidom import parseString
from event import ModuleEvent
from xmlparser.node import ModuleState
from .external.src import ratp from .external.src import ratp
nemubotversion = 3.3
nemubotversion = 3.2
def load(context): def load(context):
global DATAS global DATAS
@ -17,48 +14,37 @@ def load(context):
def help_tiny (): def help_tiny ():
"""Line inserted in the response to the command !help""" """Line inserted in the response to the command !help"""
return "Informe les usagers des prochains passages des transports en communs de la RATP" return "Informe les usagers des prochains passages des transports en communs de la RATP"
def help_full (): 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." 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, def extractInformation(msg, transport, line, station=None):
transport,
line,
station):
if station is not None and station != "": if station is not None and station != "":
times = ratp.getNextStopsAtStation(transport, line, station) times = ratp.getNextStopsAtStation(transport, line, station)
stops = "" if len(times) > 0:
for time, direction, stationname in times: (time, direction, stationname) = times[0]
station = stationname return Response(msg.sender, 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" %
stops += time+" direction "+direction+"; " (transport, line, stationname), channel=msg.channel)
if len(stops) > 0:
return Response(msg.sender, "Prochains passages du %s ligne %s à l'arrêt %s: %s" %
(transport, line, stationname, stops), msg.channel, msg.nick)
else: else:
return Response(msg.sender, "La station `%s' ne semble pas exister sur le %s ligne %s." return Response(msg.sender, "La station `%s' ne semble pas exister sur le %s ligne %s."
% (station, transport, line), msg.channel, msg.nick) % (station, transport, line), msg.channel)
else: else:
stations = ratp.getAllStations(transport, line) stations = ratp.getAllStations(transport, line)
if len(stations) > 0: if len(stations) > 0:
s = "" return Response(msg.sender, [s for s in stations], title="Stations", channel=msg.channel)
for name in stations:
s += name + "; "
return Response(msg.sender, "Stations: %s." % s, msg.channel, msg.nick)
return 0
else: else:
return Response(msg.sender, "Aucune station trouvée.", msg.channel, msg.nick) return Response(msg.sender, "Aucune station trouvée.", msg.channel)
def ask_ratp(msg): def ask_ratp(msg):
"""Hook entry from !ratp""" """Hook entry from !ratp"""
global DATAS global DATAS
if len(msg.cmd) == 4: if len(msg.cmds) == 4:
return extractInformation(msg, msg.cmd[1], msg.cmd[2], msg.cmd[3]) return extractInformation(msg, msg.cmds[1], msg.cmds[2], msg.cmds[3])
elif len(msg.cmd) == 3: elif len(msg.cmds) == 3:
return extractInformation(msg, msg.cmd[1], msg.cmd[2], None) return extractInformation(msg, msg.cmds[1], msg.cmds[2])
else: else:
return Response(msg.sender, "Mauvais usage, merci de spécifier un type de transport et une ligne, ou de consulter l'aide du module.", msg.channel, msg.nick) return Response(msg.sender, "Mauvais usage, merci de spécifier un type de transport et une ligne, ou de consulter l'aide du module.", msg.channel, msg.nick)
return False return False