1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 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)