mirror of
https://github.com/idanoo/NZCovidBot
synced 2025-07-01 19:22:14 +00:00
Update message parsing
This commit is contained in:
parent
ca3de9cadd
commit
78badbac86
1 changed files with 32 additions and 17 deletions
|
@ -3,7 +3,9 @@ package nzcovidbot
|
|||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Slice of updated located
|
||||
|
@ -34,36 +36,49 @@ func parseCsvRow(changeType string, data string) {
|
|||
|
||||
// formatCsvDiscordRow Format the string to a tidy string for the interwebs
|
||||
func formatCsvDiscordRow(data string) string {
|
||||
// Split string
|
||||
r := csv.NewReader(strings.NewReader(data))
|
||||
r.Comma = ','
|
||||
fields, err := r.Read()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
c := make([]string, 0)
|
||||
c = append(c, fields...)
|
||||
endtime := strings.Split(c[5], ", ")
|
||||
return fmt.Sprintf("**%s** %s on _%s_ - _%s_", c[1], c[2], c[4], endtime[1])
|
||||
c := parseRawRowData(data)
|
||||
return fmt.Sprintf("**%s** %s on _%s_ - _%s_", c[2], c[3], c[0], c[1])
|
||||
}
|
||||
|
||||
// formatCsvTwitterRow Format the string to a tidy string for the interwebs
|
||||
func formatCsvTwitterRow(data string) string {
|
||||
// Split string
|
||||
c := parseRawRowData(data)
|
||||
return fmt.Sprintf("New Location: *%s*no w\n%s\n_%s_ - _%s_\n#NZCovidTracker #NZCovid", c[2], c[3], c[0], c[1])
|
||||
}
|
||||
|
||||
// Returns []string of parsed
|
||||
func parseRawRowData(data string) []string {
|
||||
output := make([]string, 0)
|
||||
|
||||
r := csv.NewReader(strings.NewReader(data))
|
||||
r.Comma = ','
|
||||
fields, err := r.Read()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return ""
|
||||
return output
|
||||
}
|
||||
|
||||
c := make([]string, 0)
|
||||
c = append(c, fields...)
|
||||
endtime := strings.Split(c[5], ", ")
|
||||
return fmt.Sprintf("New Location: *%s*no w\n%s\n_%s_ - _%s_\n#NZCovidBot", c[1], c[2], c[4], endtime[1])
|
||||
|
||||
starttime := c[4]
|
||||
st, err := time.Parse("02/01/2006, 3:04 pm", starttime)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
} else {
|
||||
starttime = st.Format("Monday 2 Jan, 3:04PM")
|
||||
}
|
||||
|
||||
endtime := c[5]
|
||||
et, err := time.Parse("02/01/2006, 3:04 pm", endtime)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
endtime = strings.Split(c[5], ", ")[1]
|
||||
} else {
|
||||
endtime = et.Format("3:04PM")
|
||||
}
|
||||
|
||||
return append(output, starttime, endtime, c[1], c[2])
|
||||
}
|
||||
|
||||
func getPostableDiscordData() string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue