Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ go_import_path: cinnabot
# set -e enabled in bash.
before_script:
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/) # All the .go files, excluding vendor/
- go get github.com/golang/lint/golint # Linter
- go get honnef.co/go/tools/cmd/megacheck # Badass static analyzer/linter
- go get golang.org/x/lint/golint # Linter
- go get github.com/fzipp/gocyclo
- go get gopkg.in/telegram-bot-api.v4
- cd $GOPATH/
- git clone https://github.com/uschongensec/cinnabot.git
- cd cinnabot
- go get .
- cd $GOPATH && mkdir -p src/github.com/usdevs
- cd src/github.com/usdevs
- git clone https://github.com/usdevs/cinnabot.git && cd cinnabot
- go get ./...

# script always run to completion (set +e). All of these code checks are must haves
# in a modern Go project.
script:
- test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt
- go test -v -race ./... # Run all the tests with the race detector enabled
- go vet ./... # go vet is the official Go static analyzer
- megacheck ./... # "go vet on steroids" + linter
- gocyclo -over 19 $GO_FILES # forbid code with huge functions
- golint -set_exit_status $(go list ./...) # one last linter
27 changes: 24 additions & 3 deletions travel.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@ import (
tgbotapi "gopkg.in/telegram-bot-api.v4"
)

//Structs for BusTiming
// BusTimes :
// Services - An array of Services
type BusTimes struct {
Services []Service `json:"Services"`
}

// Service : An incoming bus.
type Service struct {
ServiceNum string `json:"ServiceNo"`
Next NextBus `json:"NextBus"`
Next2 NextBus `json:"NextBus2"`
Next3 NextBus `json:"NextBus3"`
}

// NextBus : has EstimatedArrival, time at which the bus is expected to arrive
type NextBus struct {
EstimatedArrival string `json:"EstimatedArrival"`
}

//BusTimings checks the bus timings based on given location
// BusTimings checks the bus timings based on given location
func (cb *Cinnabot) BusTimings(msg *message) {
if len(msg.Args) == 0 || !cb.CheckArgCmdPair("/publicbus", msg.Args) {
opt1 := tgbotapi.NewKeyboardButtonRow(tgbotapi.NewKeyboardButton("Cinnamon"))
Expand Down Expand Up @@ -98,13 +103,29 @@ func busTimingResponse(BSH *BusStopHeap) string {
if err := json.Unmarshal(responseData, &bt); err != nil {
log.Print(err)
}

// iteratively add message about each bus service at the buststop
for j := 0; j < len(bt.Services); j++ {
arrivalTime := bt.Services[j].Next.EstimatedArrival
arrivalTime2 := bt.Services[j].Next2.EstimatedArrival

layout := "2006-01-02T15:04:05-07:00"
t, _ := time.Parse(layout, arrivalTime)
t2, _ := time.Parse(layout, arrivalTime2)
duration := int(t.Sub(time.Now()).Minutes())
returnMessage += "🚍Bus " + bt.Services[j].ServiceNum + " : " + strconv.Itoa(duration+1) + " minutes\n"

durStr := strconv.Itoa(duration)
durStr2 := strconv.Itoa(int(t2.Sub(time.Now()).Minutes()))

if duration < 0 { // no bus
returnMessage += "🛑Bus" + bt.Services[j].ServiceNum + " : - mins\n"
} else if duration == 1 { // singular noun
returnMessage += "🚍" + bt.Services[j].ServiceNum + " : " + durStr + " min, " + durStr2 + " mins\n"
} else if duration == 0 { // arriving
returnMessage += "🚍" + bt.Services[j].ServiceNum + " : Arr, " + durStr2 + " mins\n"
} else {
returnMessage += "🚍" + bt.Services[j].ServiceNum + " : " + durStr + " mins, " + durStr2 + " mins\n"
}
}
returnMessage += "\n"
}
Expand Down