You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
db, err := parseData()
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
selected := []*station{}
|
|
|
|
terminal := bufio.NewReader(os.Stdin)
|
|
fmt.Println("Select the station you want to create a route for. Press f to finish.")
|
|
fmt.Println()
|
|
s := 1
|
|
for {
|
|
fmt.Printf("Station %d: ", s)
|
|
station, err := terminal.ReadString('\n')
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
station = station[:len(station)-1]
|
|
if station == "f" {
|
|
break
|
|
}
|
|
stations, err := findStations(db, station)
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
if len(stations) == 0 {
|
|
fmt.Println("No stations found")
|
|
continue
|
|
}
|
|
if len(stations) > 1 {
|
|
fmt.Println("Multiple stations found")
|
|
for i, s := range stations {
|
|
fmt.Printf("%d: %s (%s)\n", i+1, s.name, s.id)
|
|
}
|
|
continue
|
|
}
|
|
selected = append(selected, stations[0])
|
|
s++
|
|
}
|
|
|
|
if len(selected) < 2 {
|
|
fmt.Println("You need to select at least two stations")
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Println("\nYour gpx:")
|
|
gpx := createRoute(selected)
|
|
gpx.WriteIndent(os.Stdout, "", " ")
|
|
fmt.Println()
|
|
}
|