diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 23cf4a0..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "modules/nextstop/external"] - path = modules/nextstop/external - url = git://github.com/nbr23/NextStop.git diff --git a/modules/nextstop.py b/modules/nextstop.py new file mode 100644 index 0000000..7f4b211 --- /dev/null +++ b/modules/nextstop.py @@ -0,0 +1,74 @@ +"""Informe les usagers des prochains passages des transports en communs de la RATP""" + +# PYTHON STUFFS ####################################################### + +from nemubot.exception import IMException +from nemubot.hooks import hook +from more import Response + +from nextstop import ratp + +@hook.command("ratp", + help="Affiche les prochains horaires de passage", + help_usage={ + "TRANSPORT": "Affiche les lignes du moyen de transport donné", + "TRANSPORT LINE": "Affiche les stations sur la ligne de transport donnée", + "TRANSPORT LINE STATION": "Affiche les prochains horaires de passage à l'arrêt donné", + "TRANSPORT LINE STATION DESTINATION": "Affiche les prochains horaires de passage dans la direction donnée", + }) +def ask_ratp(msg): + l = len(msg.args) + + transport = msg.args[0] if l > 0 else None + line = msg.args[1] if l > 1 else None + station = msg.args[2] if l > 2 else None + direction = msg.args[3] if l > 3 else None + + if station is not None: + times = sorted(ratp.getNextStopsAtStation(transport, line, station, direction), key=lambda i: i[0]) + + if len(times) == 0: + raise IMException("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 line is not None: + stations = ratp.getAllStations(transport, line) + + if len(stations) == 0: + raise IMException("aucune station trouvée.") + return Response(stations, title="Stations", channel=msg.channel) + + elif transport is not None: + lines = ratp.getTransportLines(transport) + if len(lines) == 0: + raise IMException("aucune ligne trouvée.") + return Response(lines, title="Lignes", channel=msg.channel) + + else: + raise IMException("précise au moins un moyen de transport.") + + +@hook.command("ratp_alert", + help="Affiche les perturbations en cours sur le réseau") +def ratp_alert(msg): + if len(msg.args) == 0: + raise IMException("précise au moins un moyen de transport.") + + l = len(msg.args) + transport = msg.args[0] if l > 0 else None + line = msg.args[1] if l > 1 else None + + if line is not None: + d = ratp.getDisturbanceFromLine(transport, line) + if "date" in d and d["date"] is not None: + incidents = "Au {date[date]}, {title}: {message}".format(**d) + else: + incidents = "{title}: {message}".format(**d) + else: + incidents = ratp.getDisturbance(None, transport) + + return Response(incidents, channel=msg.channel, nomore="No more incidents", count=" (%d more incidents)") diff --git a/modules/nextstop/__init__.py b/modules/nextstop/__init__.py deleted file mode 100644 index 9530ab8..0000000 --- a/modules/nextstop/__init__.py +++ /dev/null @@ -1,55 +0,0 @@ -# coding=utf-8 - -"""Informe les usagers des prochains passages des transports en communs de la RATP""" - -from nemubot.exception import IMException -from nemubot.hooks import hook -from more import Response - -nemubotversion = 3.4 - -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." - - -@hook.command("ratp") -def ask_ratp(msg): - """Hook entry from !ratp""" - if len(msg.args) >= 3: - transport = msg.args[0] - line = msg.args[1] - station = msg.args[2] - if len(msg.args) == 4: - times = ratp.getNextStopsAtStation(transport, line, station, msg.args[3]) - else: - times = ratp.getNextStopsAtStation(transport, line, station) - - if len(times) == 0: - raise IMException("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.args) == 2: - stations = ratp.getAllStations(msg.args[0], msg.args[1]) - - if len(stations) == 0: - raise IMException("aucune station trouvée.") - return Response([s for s in stations], title="Stations", channel=msg.channel) - - else: - raise IMException("Mauvais usage, merci de spécifier un type de transport et une ligne, ou de consulter l'aide du module.") - -@hook.command("ratp_alert") -def ratp_alert(msg): - if len(msg.args) == 2: - transport = msg.args[0] - cause = msg.args[1] - incidents = ratp.getDisturbance(cause, transport) - return Response(incidents, channel=msg.channel, nomore="No more incidents", count=" (%d more incidents)") - else: - raise IMException("Mauvais usage, merci de spécifier un type de transport et un type d'alerte (alerte, manif, travaux), ou de consulter l'aide du module.") diff --git a/modules/nextstop/external b/modules/nextstop/external deleted file mode 160000 index 3d5c9b2..0000000 --- a/modules/nextstop/external +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d5c9b2d52fbd214f5aaad00e5f3952de919b3e5