42 lines
1,010 B
Nim
42 lines
1,010 B
Nim
import ../types
|
|
import ../util
|
|
import ./products
|
|
import json
|
|
import options
|
|
|
|
proc mkParseLine*(commonOperators: seq[Operator]): proc =
|
|
proc parseLine(l: JsonNode): Option[Line] =
|
|
# unparsable
|
|
if l{"cls"}.getInt == 0:
|
|
return options.none(Line)
|
|
|
|
let line = l.to(HafasProd)
|
|
var res = Line()
|
|
|
|
res.name = line.name
|
|
res.product = parseProduct(line.cls)
|
|
res.tripNum = line.prodCtx.num
|
|
res.productName = line.prodCtx.catOut
|
|
res.fullProductName = line.prodCtx.catOutL
|
|
res.id = slug(line.prodCtx.lineId.get(line.name))
|
|
|
|
if line.opX.isSome:
|
|
res.operator = some(commonOperators[line.opX.get])
|
|
|
|
# DB
|
|
|
|
if line.nameS.isSome and (res.product == bus or res.product == tram or res.product == ferry):
|
|
res.name = line.nameS.get
|
|
|
|
if line.addName.isSome:
|
|
# swap name and addName
|
|
res.additionalName = some(res.name)
|
|
res.name = line.addName.get
|
|
|
|
# End DB
|
|
|
|
res.mode = MODES[int(res.product)]
|
|
return some(res)
|
|
|
|
return parseLine
|