diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index dca2950..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "src/hafas"] - path = src/hafas - url = https://cgit.ctu.cx/hafas.nim diff --git a/oeffisearch.nimble b/oeffisearch.nimble index 5cc114b..a9094c5 100644 --- a/oeffisearch.nimble +++ b/oeffisearch.nimble @@ -12,3 +12,4 @@ bin = @["oeffisearch"] # Dependencies requires "nim >= 1.0.4" +requires "https://cgit.ctu.cx/hafas.nim" diff --git a/src/cache.nim b/src/cache.nim index ecbff10..725399f 100644 --- a/src/cache.nim +++ b/src/cache.nim @@ -1,5 +1,6 @@ import tables, random, os, times, json, asyncfile, asyncdispatch import types, cache_types, utils +import hafas randomize() diff --git a/src/cache_types.nim b/src/cache_types.nim index b6e81c5..dc70faf 100644 --- a/src/cache_types.nim +++ b/src/cache_types.nim @@ -1,5 +1,5 @@ import tables -import types +import hafas type moreJourneysMode* = enum diff --git a/src/endpoints/journeys.nim b/src/endpoints/journeys.nim index 7b4fdc9..c62c22a 100644 --- a/src/endpoints/journeys.nim +++ b/src/endpoints/journeys.nim @@ -1,5 +1,6 @@ import json, tables, options, asyncdispatch -import ../types, ../hafas/hafas, ../cache +import hafas +import ../types, ../cache when not defined(release): import hotcodereloading diff --git a/src/endpoints/moreJourneys.nim b/src/endpoints/moreJourneys.nim index f1aac8b..360d451 100644 --- a/src/endpoints/moreJourneys.nim +++ b/src/endpoints/moreJourneys.nim @@ -1,5 +1,6 @@ import json, tables, options, asyncdispatch, strutils -import ../types, ../cache_types, ../hafas/hafas, ../cache +import hafas +import ../types, ../cache_types, ../cache proc moreJourneysEndpoint*(requestData: JsonNode): Future[JsonNode] {.async.} = var reqId = requestData{"reqId"}.getStr() diff --git a/src/endpoints/refreshJourney.nim b/src/endpoints/refreshJourney.nim index 5d2ea15..b05c053 100644 --- a/src/endpoints/refreshJourney.nim +++ b/src/endpoints/refreshJourney.nim @@ -1,5 +1,6 @@ import json, tables, options, asyncdispatch, strutils -import ../types, ../cache_types, ../hafas/hafas, ../cache +import hafas +import ../types, ../cache_types, ../cache proc refreshJourneyEndpoint*(requestData: JsonNode): Future[JsonNode] {.async.} = let reqId = requestData{"reqId"}.getStr() diff --git a/src/endpoints/suggestions.nim b/src/endpoints/suggestions.nim index c598089..64b8461 100644 --- a/src/endpoints/suggestions.nim +++ b/src/endpoints/suggestions.nim @@ -1,5 +1,5 @@ import json, options, asyncdispatch -import ../types, ../hafas/hafas +import hafas const ds100Json = staticRead "../../ds100reverse.json" diff --git a/src/hafas b/src/hafas deleted file mode 160000 index e815bbf..0000000 --- a/src/hafas +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e815bbfd2ef4f49c4e3a757739a60d802bcc53f5 diff --git a/src/types.nim b/src/types.nim index 39042d0..5e7eaa8 100644 --- a/src/types.nim +++ b/src/types.nim @@ -1,4 +1,3 @@ -import options import asynchttpserver type @@ -7,199 +6,5 @@ type msg*: string headers*: HttpHeaders - Stop* = object - id*: string - name*: string - location*: Location - products*: Products - station*: Option[Station] - - Station* = object - id*: int - name*: string - location*: Location - products*: Products - - Location* = object - latitude*: float - longitude*: float - name*: Option[string] - address*: Option[string] - id*: Option[string] - - Product* = enum - nationalExp, national, regionalExp, regional, suburban, bus, ferry, subway, tram, taxi - - Mode* = enum - Train, Bus, Watercraft, Taxi, Walking - - Products* = object - nationalExp*: bool - national*: bool - regionalExp*: bool - regional*: bool - suburban*: bool - bus*: bool - ferry*: bool - subway*: bool - tram*: bool - taxi*: bool - - Point* = object - stop*: Option[Stop] - location*: Option[Location] - - Journey* = object - refreshToken*: string - lastUpdated*: int64 - legs*: seq[Leg] - cycle*: Option[Cycle] - price*: Option[Price] - - LegPart* = object - point*: Point - plannedTime*: int64 - prognosedTime*: Option[int64] - plannedPlatform*: Option[string] - prognosedPlatform*: Option[string] - - Leg* = object - isWalking*: bool - isTransfer*: bool - cancelled*: bool - departure*: LegPart - arrival*: LegPart - polyline*: Option[Polyline] - distance*: Option[int] # required for isWalking or isTransfer - tripId*: Option[string] # required for not isWalking and not isTranfer - line*: Option[Line] # required for not isWalking and not isTranfer - direction*: Option[string] # required for not isWalking and not isTranfer - cycle*: Option[Cycle] - stopovers*: Option[seq[Stopover]] - remarks*: Option[seq[Remark]] - - Line* = object - id*: string - name*: string - mode*: Mode - product*: Product - tripNum*: string - productName*: string - fullProductName*: string - operator*: Option[Operator] - additionalName*: Option[string] - trainType*: Option[string] - trainTypeShort*: Option[string] - - Operator* = object - id*: string - name*: string - - Cycle* = object - min*: Option[int] - max*: Option[int] - nr*: Option[int] - - # TODO: Make this unnecessary :3 - Price* = object - amount*: float - currency*: Option[string] - - StopoverPart* = object - plannedTime*: Option[int64] - prognosedTime*: Option[int64] - plannedPlatform*: Option[string] - prognosedPlatform*: Option[string] - - Stopover* = object - stop*: Stop - cancelled*: bool - departure*: StopoverPart - arrival*: StopoverPart - - Remark* = object - `type`*: Option[string] - code*: Option[string] - summary*: Option[string] - text*: Option[string] - tripId*: Option[string] - - JourneysResponse* = object - earlierRef*: string - laterRef*: string - journeys*: seq[Journey] - - Accessibility* = enum - none, partial, complete - - SuggestionsParams* = object - query*: string - results*: Option[int] #default value: 10 - stations*: Option[bool] #default value: true - poi*: Option[bool] #default value: true - addresses*: Option[bool] #default value: true - - JourneysParams* = object - fromPoint*: Point - toPoint*: Point - viaPoint*: Option[Point] #default value: null support in hafas backend: ✅ - earlierRef*: Option[string] #default value: null support in hafas backend: ✅ - laterRef*: Option[string] #default value: null support in hafas backend: ✅ - results*: Option[int] #default value: 5 support in hafas backend: ✅ - stopovers*: Option[bool] #default value: false support in hafas backend: ✅ - polylines*: Option[bool] #default value: false support in hafas backend: ✅ - remarks*: Option[bool] #default value: true support in hafas backend: - bikeFriendly*: Option[bool] #default value: false support in hafas backend: - tickets*: Option[bool] #default value: false support in hafas backend: ✅ - startWithWalking*: Option[bool] #default value: true support in hafas backend: ✅ - scheduledDays*: Option[bool] - accessibility*: Option[Accessibility] #default value: none support in hafas backend: ✅ - transfers*: Option[int] #default value: -1 support in hafas backend: ✅ - transferTime*: Option[int] #default value: 00 support in hafas backend: ✅ - arrival*: Option[int64] #default value: null support in hafas backend: ✅ - departure*: Option[int64] #default value: null support in hafas backend: ✅ - products*: Option[Products] #default value: all true support in hafas backend: ✅ - - RefreshJourneyParams* = object - refreshToken*: string - stopovers*: Option[bool] #default value: false support in hafas backend: ✅ - polylines*: Option[bool] #default value: false support in hafas backend: ✅ - tickets*: Option[bool] #default value: false support in hafas backend: ✅ - - Polyline* = object - `type`*: string - features*: seq[Feature] - - Feature* = object - `type`*: string - properties*: Option[Stop] - geometry*: FeatureGeometry - - FeatureGeometry* = object - `type`*: string - coordinates*: seq[float] - - notFoundException* = object of ValueError errorException* = object of ValueError - - hafasExceptionKind* = enum - SERVER_ERROR, ACCESS_DENIED, INVALID_REQUEST, NOT_FOUND - - hafasException* = ref object of ValueError - code*: hafasExceptionKind - message*: string - statusCode*: HttpCode - -const MODES* = [ - Train, # nationalExp - Train, # national - Train, # regionalExp - Train, # regional - Train, # suburban - Bus, # bus - Watercraft, # ferry - Train, # subway - Train, # tram - Taxi, # taxi -]