Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

String Cleanup #6

Merged
merged 3 commits into from Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions cmd/api.go
Expand Up @@ -8,12 +8,14 @@ Copyright © 2019 Graham Plata <graham.plata@gmail.com>
import (
"encoding/json"
"fmt"
"github.com/briandowns/spinner"
"github.com/grahamplata/sixers/schema"
"github.com/logrusorgru/aurora"
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/briandowns/spinner"
"github.com/grahamplata/sixers/schema"
"github.com/logrusorgru/aurora"
)

func buildURL(val1 string, val2 string) string {
Expand All @@ -32,8 +34,9 @@ func handleNextResponse(response *http.Response) bool {
for i := 0; i < len(responseObject.Data); i++ {
cleanTime := fmt.Sprintf("%sT00:00:00.000Z", t)
if responseObject.Data[i].Date == cleanTime {
sixers := fmt.Sprintf("%d%ders", aurora.Bold(aurora.Red(7)), aurora.Bold(aurora.Blue(6)))
fmt.Printf("10,9 8 %s!\nYou're in luck! There is a game today @ %s %s!\n", sixers, responseObject.Data[i].Status, responseObject.Data[i].Time)
status := responseObject.Data[i].Status
gameTime := strings.TrimRight(responseObject.Data[i].Time, " ")
fmt.Printf("10,9 8 %s! There is a game currently @ %s %+s\n", sixers, status, gameTime)
gameFound = true
}
}
Expand Down Expand Up @@ -72,6 +75,8 @@ func handleRecordResponse(response *http.Response) string {
}
}
spin.Stop()
pct := (float64(winRecord) / float64(gameCount))
return fmt.Sprintf("Wins: %d Losses: %d Winrate: %.3f\n", winRecord, (gameCount - winRecord), pct)
wins := fmt.Sprintf("%s %d", aurora.Green("Wins:"), winRecord)
losses := fmt.Sprintf("%s %d", aurora.Red("Losses:"), (gameCount - winRecord))
pct := fmt.Sprintf("%s %.3f", aurora.Yellow("Win pct:"), (float64(winRecord) / float64(gameCount)))
return fmt.Sprintf("%s\n%s\n%s", wins, losses, pct)
}
8 changes: 8 additions & 0 deletions cmd/config.go
@@ -1,8 +1,16 @@
package cmd

import (
"fmt"

"github.com/logrusorgru/aurora"
)

/*
Copyright © 2019 Graham Plata <graham.plata@gmail.com>

*/

const baseAPIURL string = "https://www.balldontlie.io/api/v1/games"

var sixers string = fmt.Sprintf("%d%ders", aurora.Bold(aurora.Red(7)), aurora.Bold(aurora.Blue(6)))