From 596501b9c2d7ac1752fc97e0fa6d0e74223f77bf Mon Sep 17 00:00:00 2001 From: Lukas Winkler Date: Mon, 1 Aug 2016 14:14:46 +0200 Subject: [PATCH] =?UTF-8?q?Abfrage=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.py | 20 ++++++++++++++++++-- wienerLinien.py | 19 ++++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index f9a639a..7ec44bb 100644 --- a/bot.py +++ b/bot.py @@ -28,7 +28,7 @@ from save import PersistentData # Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) + level=logging.DEBUG) logger = logging.getLogger(__name__) @@ -79,7 +79,7 @@ def addstation(bot, update, args): bot.sendMessage(update.message.chat_id, text="Station '{station}' hinzugefügt".format(station=choice[0][0])) else: - message = "Es wurden mehrere Stationen gefunden.\nBitte gib die Nummer der gewünschten Station an:\n" + message = "Es wurden mehrere Stationen gefunden.\nBitte wähle die gewünschten Station aus:" keyboard = [] i = 1 for name, percentage, stationId in choice: @@ -127,6 +127,20 @@ def list_stations(bot, update): "mit /add kannst du eine neue Station hinzufügen") +def departures(bot, update): + message = "" + stations = save.get_stations(update.message.chat_id) + for station in stations: + for platform in wl.get_platforms(station["id"]): + if "RBL_NUMMER" in platform and platform["RBL_NUMMER"]: + dep, line, towards = wl.nexttrains(platform["RBL_NUMMER"]) + message += "{station} Linie {line} Richtung {richtung}: {min}\n".format(station=station["name"], + richtung=towards, + line=line, + min=", ".join(map(str, dep))) + bot.sendMessage(update.message.chat_id, text=message) + + def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(TOKEN) @@ -139,6 +153,8 @@ def main(): dp.add_handler(CommandHandler("help", help_message)) dp.add_handler(CommandHandler("list", list_stations)) dp.add_handler(CommandHandler('add', addstation, pass_args=True)) + dp.add_handler(CommandHandler("check", departures)) + dp.add_handler(CallbackQueryHandler(select)) # conv_handler = ConversationHandler( diff --git a/wienerLinien.py b/wienerLinien.py index 7c7e768..51799ca 100644 --- a/wienerLinien.py +++ b/wienerLinien.py @@ -23,17 +23,20 @@ class WienerLinien: def api(rbl): parameters = {"rbl": rbl, "sender": wienerlinien_API_key} r = requests.get("https://www.wienerlinien.at/ogd_realtime/monitor", params=parameters) + print(r.status_code) return r.json() def nexttrains(self, rbl): response = self.api(rbl) countdowns = [] + name = response["data"]["monitors"][0]["lines"][0]["name"] + towards = response["data"]["monitors"][0]["lines"][0]["towards"] for departure in response["data"]["monitors"][0]["lines"][0]["departures"]["departure"]: countdowns.append(departure["departureTime"]["countdown"]) - return countdowns + return countdowns, name, towards def fuzzy_stationname(self, userinput): - output = process.extract(userinput, self.stationNames, limit=6, scorer=fuzz.partial_ratio) + output = process.extract(userinput, self.stationNames, limit=6, scorer=fuzz.UQRatio) choice = [] for i in range(len(output)): if i == 0: @@ -56,8 +59,11 @@ class WienerLinien: number = int(input()) pprint(result[number - 1][2]) - def getStationInfo(self, stationId): - return self.stations[str(stationId)] + def getStationInfo(self, station_id): + return self.stations[str(station_id)] + + def get_platforms(self, station_id): + return self.stations[str(station_id)]["PLATFORMS"] def main(): @@ -65,7 +71,10 @@ def main(): # pprint(wl.stations["214461789"]) # pprint(wl.nexttrains(4431)) - pprint(wl.fuzzy_stationname("Heiligenstadt")) + station = wl.fuzzy_stationname("Rossauer Lände") + pprint(station[0]) + for platform in wl.get_platforms(station[0][2]): + pprint(wl.nexttrains(platform["RBL_NUMMER"])) if __name__ == '__main__':