import asyncdispatch, telebot, strutils, osproc, json, os, httpClient proc ds100Command* (bot: Telebot, command: Command): Future[bool] {.async.} = var rückgabewert = "" var location = false var longitude = 0.0 var latitude = 0.0 let anfrage = toUpperAscii(command.params) if anfrage != "": let daten = parseJson(readFile(getEnv("ASSETS_PATH") & "/db/ds100.json")) if daten.hasKey(anfrage): let id = daten[anfrage]["ibnr"].getStr let stationsDaten = parseJson(readFile(getEnv("ASSETS_PATH") & "/db/stations/" & id & ".json")) rückgabewert = "Name: " & stationsDaten["name"].getStr & "\n" rückgabewert &= "IBNR: " & stationsDaten["id"].getStr & "\n" rückgabewert &= "Kategorie: " & $stationsDaten["category"].getInt & "\n" if stationsDaten["hasDBLounge"].getBool: rückgabewert &= "Mit DB Lounge" & "\n" if stationsDaten["hasSteplessAccess"].getStr == "yes": rückgabewert &= "Mit stufenfreiem Zugang" & "\n" if stationsDaten["hasSteplessAccess"].getStr == "partial": rückgabewert &= "Mit teilweise stufenfreiem Zugang" & "\n" if stationsDaten["hasPublicFacilities"].getBool: rückgabewert &= "Mit Bahnhofstoiletten" & "\n" longitude = stationsDaten["longitude"].getFloat latitude = stationsDaten["latitude"].getFloat location = true # This Code Works, but only at some Stations. Example: AK is fine, BLO crashes. # Exception message: Bad Request: can't parse entities: Can't find end of the entity starting at byte offset # # var httpClient = newAsyncHttpClient() # if daten[anfrage].hasKey("RailwayMapId"): # # Debug # echo daten[anfrage]["RailwayMapId"].getInt # let photojson = parseJson(await httpClient.getContent("https://api.railway-stations.org/de/stations/" & $daten[anfrage]["RailwayMapId"].getInt)) # if photojson.hasKey("photoUrl"): # let fotourl = replace($photojson["photoUrl"], "\"", "") # # Debug # echo fotourl # rückgabewert &= $fotourl else: rückgabewert = "hab ich nicht" else: rückgabewert = "leere anfrage" discard await bot.sendMessage(command.message.chat.id, rückgabewert, replyToMessageId = command.message.messageId, parseMode = "markdown") if location: discard await bot.sendLocation(command.message.chat.id, longitude=longitude, latitude=latitude)