golifehk/datasources/kmb/QueryResult.go

59 lines
1.5 KiB
Go
Raw Normal View History

2022-09-16 20:33:47 +00:00
package kmb
import (
2022-09-16 22:42:49 +00:00
"fmt"
2022-09-16 20:33:47 +00:00
"strings"
query "github.com/tgckpg/golifehk/query"
utils "github.com/tgckpg/golifehk/utils"
)
type QueryResult struct {
Lang string
Error error
Query *query.QueryObject
}
func ( this *QueryResult ) Message() ( string, error ) {
if this.Error != nil {
return "", this.Error
}
sb := strings.Builder{}
if 0 < len( *this.Query.Results ) {
// Print Stop Name, the print the list of routes
if this.Query.Key == "" {
for _, item := range *this.Query.Results {
var b *BusStop
b = any( item ).( *BusStop )
if b.Routes == nil {
continue
}
utils.WriteMDv2Text( &sb, (*b.Name)[ this.Lang ] )
sb.WriteString( "\n " )
for _, route := range *b.Routes {
utils.WriteMDv2Text( &sb, route.RouteId )
2022-09-16 22:42:49 +00:00
if route.Direction == "O" {
sb.WriteString( "↑" )
} else if route.Direction == "I" {
sb.WriteString( "↓" )
}
if route.ServiceType != "1" {
utils.WriteMDv2Text( &sb, utils.ToPower( route.ServiceType ) )
}
2022-09-16 20:33:47 +00:00
sb.WriteString( " " )
}
sb.WriteString( "\n" )
}
}
2022-09-16 22:42:49 +00:00
fmt.Print( this.Query.Key )
} else {
2022-09-16 20:33:47 +00:00
}
return sb.String(), nil
}