Abfrage hinzugefügt
This commit is contained in:
parent
4981f3eb21
commit
596501b9c2
2 changed files with 32 additions and 7 deletions
20
bot.py
20
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(
|
||||
|
|
|
@ -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__':
|
||||
|
|
Reference in a new issue