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
|
# Enable logging
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.INFO)
|
level=logging.DEBUG)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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]))
|
bot.sendMessage(update.message.chat_id, text="Station '{station}' hinzugefügt".format(station=choice[0][0]))
|
||||||
|
|
||||||
else:
|
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 = []
|
keyboard = []
|
||||||
i = 1
|
i = 1
|
||||||
for name, percentage, stationId in choice:
|
for name, percentage, stationId in choice:
|
||||||
|
@ -127,6 +127,20 @@ def list_stations(bot, update):
|
||||||
"mit /add kannst du eine neue Station hinzufügen")
|
"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():
|
def main():
|
||||||
# Create the EventHandler and pass it your bot's token.
|
# Create the EventHandler and pass it your bot's token.
|
||||||
updater = Updater(TOKEN)
|
updater = Updater(TOKEN)
|
||||||
|
@ -139,6 +153,8 @@ def main():
|
||||||
dp.add_handler(CommandHandler("help", help_message))
|
dp.add_handler(CommandHandler("help", help_message))
|
||||||
dp.add_handler(CommandHandler("list", list_stations))
|
dp.add_handler(CommandHandler("list", list_stations))
|
||||||
dp.add_handler(CommandHandler('add', addstation, pass_args=True))
|
dp.add_handler(CommandHandler('add', addstation, pass_args=True))
|
||||||
|
dp.add_handler(CommandHandler("check", departures))
|
||||||
|
|
||||||
dp.add_handler(CallbackQueryHandler(select))
|
dp.add_handler(CallbackQueryHandler(select))
|
||||||
|
|
||||||
# conv_handler = ConversationHandler(
|
# conv_handler = ConversationHandler(
|
||||||
|
|
|
@ -23,17 +23,20 @@ class WienerLinien:
|
||||||
def api(rbl):
|
def api(rbl):
|
||||||
parameters = {"rbl": rbl, "sender": wienerlinien_API_key}
|
parameters = {"rbl": rbl, "sender": wienerlinien_API_key}
|
||||||
r = requests.get("https://www.wienerlinien.at/ogd_realtime/monitor", params=parameters)
|
r = requests.get("https://www.wienerlinien.at/ogd_realtime/monitor", params=parameters)
|
||||||
|
print(r.status_code)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def nexttrains(self, rbl):
|
def nexttrains(self, rbl):
|
||||||
response = self.api(rbl)
|
response = self.api(rbl)
|
||||||
countdowns = []
|
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"]:
|
for departure in response["data"]["monitors"][0]["lines"][0]["departures"]["departure"]:
|
||||||
countdowns.append(departure["departureTime"]["countdown"])
|
countdowns.append(departure["departureTime"]["countdown"])
|
||||||
return countdowns
|
return countdowns, name, towards
|
||||||
|
|
||||||
def fuzzy_stationname(self, userinput):
|
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 = []
|
choice = []
|
||||||
for i in range(len(output)):
|
for i in range(len(output)):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
|
@ -56,8 +59,11 @@ class WienerLinien:
|
||||||
number = int(input())
|
number = int(input())
|
||||||
pprint(result[number - 1][2])
|
pprint(result[number - 1][2])
|
||||||
|
|
||||||
def getStationInfo(self, stationId):
|
def getStationInfo(self, station_id):
|
||||||
return self.stations[str(stationId)]
|
return self.stations[str(station_id)]
|
||||||
|
|
||||||
|
def get_platforms(self, station_id):
|
||||||
|
return self.stations[str(station_id)]["PLATFORMS"]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -65,7 +71,10 @@ def main():
|
||||||
|
|
||||||
# pprint(wl.stations["214461789"])
|
# pprint(wl.stations["214461789"])
|
||||||
# pprint(wl.nexttrains(4431))
|
# 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__':
|
if __name__ == '__main__':
|
||||||
|
|
Reference in a new issue