Fixed mtr new csv format
This commit is contained in:
parent
726916ed45
commit
e4275f60b7
@ -87,7 +87,7 @@ func ( this QueryResult ) Message() ( string, error ) {
|
||||
|
||||
for _, d := range keys {
|
||||
b := st[ d ]
|
||||
sb.WriteString( q.Key )
|
||||
utils.WriteMDv2Text( &sb, q.Key )
|
||||
|
||||
if d == "O" {
|
||||
sb.WriteString( "↑" )
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
query "github.com/tgckpg/golifehk/query"
|
||||
"github.com/tgckpg/golifehk/utils"
|
||||
@ -30,7 +29,6 @@ func readBusStopData( r io.Reader ) ( *map[string] *BusStop, error ) {
|
||||
for i, line := range entries {
|
||||
if i == 0 {
|
||||
headers = line
|
||||
line[0] = strings.TrimLeft( line[0], utils.BOM )
|
||||
continue
|
||||
}
|
||||
|
||||
@ -43,8 +41,8 @@ func readBusStopData( r io.Reader ) ( *map[string] *BusStop, error ) {
|
||||
case "DIRECTION":
|
||||
entry.Direction = value
|
||||
case "STATION_SEQNO":
|
||||
v, _ := strconv.Atoi( value )
|
||||
entry.StationSeq = v
|
||||
v, _ := strconv.ParseFloat( value, 64 )
|
||||
entry.StationSeq = int( v )
|
||||
case "STATION_ID":
|
||||
entry.StationId = value
|
||||
case "STATION_LATITUDE":
|
||||
@ -106,6 +104,7 @@ func getBusStops() (*[] query.ISearchable, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
utils.ReadBOM( buff )
|
||||
busStopMap, err := readBusStopData( buff )
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
2
main.go
2
main.go
@ -71,7 +71,7 @@ func main() {
|
||||
}
|
||||
|
||||
if !isGroup && !f_sent && f_err != nil {
|
||||
mesg := fmt.Sprintf( "%s", f_err )
|
||||
mesg := utils.MDv2Text( fmt.Sprintf( "%s", f_err ) )
|
||||
botsend( bot, &update, &mesg )
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -16,6 +17,17 @@ func WriteMDv2Text( sb *strings.Builder, t string ) {
|
||||
sb.WriteString( t )
|
||||
}
|
||||
|
||||
func MDv2Text( t string ) string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
for _, c := range MARKDOWN_ESC {
|
||||
t = strings.Replace( t, c, "\\" + c, -1 )
|
||||
}
|
||||
|
||||
sb.WriteString( t )
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func ToPower( t string ) string {
|
||||
for s, r := range POWER_NUMBERS {
|
||||
t = strings.ReplaceAll( t, s, r )
|
||||
@ -23,6 +35,26 @@ func ToPower( t string ) string {
|
||||
return t
|
||||
}
|
||||
|
||||
func ReadBOM( buff *bytes.Buffer ) {
|
||||
b, _ := buff.ReadByte()
|
||||
if b != 0xef {
|
||||
buff.UnreadByte()
|
||||
return
|
||||
}
|
||||
b, _ = buff.ReadByte()
|
||||
if b != 0xbb {
|
||||
buff.UnreadByte()
|
||||
buff.UnreadByte()
|
||||
return
|
||||
}
|
||||
b, _ = buff.ReadByte()
|
||||
if b != 0xbf {
|
||||
buff.UnreadByte()
|
||||
buff.UnreadByte()
|
||||
buff.UnreadByte()
|
||||
}
|
||||
}
|
||||
|
||||
func TryGetEnv[T any]( name string, fallback T ) T {
|
||||
v := os.Getenv( name )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user