Skip to content

Commit ddc5b7a

Browse files
authored
Merge pull request #8 from tfreder1ck/sort-by
Added sort by option for H2H tables
2 parents ee34f33 + 774b612 commit ddc5b7a

33 files changed

+457
-106
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ go.work
2424
.env
2525

2626
*.DS_Store
27+
28+
#logs
29+
output.txt

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ package main
66

77
import (
88
"log"
9+
"os"
910

11+
"github.com/dos-2/oddshub/models"
1012
"github.com/dos-2/oddshub/ui"
1113
)
1214

1315
func main() {
1416

17+
if len(os.Args) > 1 {
18+
for _, arg := range os.Args[1:] {
19+
switch arg {
20+
case "debug":
21+
models.SetDebug(true)
22+
}
23+
}
24+
}
25+
1526
if err := ui.RunApp(); err != nil {
1627
log.Fatalf("Failed to run application: %v", err)
1728
}

models/store.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2024 dos-2
3+
* All rights reserved.
4+
*/
5+
package models
6+
7+
import (
8+
"fmt"
9+
"time"
10+
)
11+
12+
var loadedEvents = make(map[string][]Event)
13+
14+
func AddLoadedEvent(key string, value []Event) {
15+
tempMap := loadedEvents
16+
tempMap[key] = value
17+
loadedEvents = tempMap
18+
}
19+
20+
func GetLoadedEvents(key string) []Event {
21+
return loadedEvents[key]
22+
}
23+
24+
var currentPage = ""
25+
26+
func SetCurrentPage(page string) {
27+
currentPage = page
28+
}
29+
30+
func GetCurrentPage() string {
31+
return currentPage
32+
}
33+
34+
var currentPageIndex = ""
35+
36+
func SetCurrentPageIndex(index string) {
37+
currentPageIndex = index
38+
}
39+
40+
func GetCurrentPageIndex() string {
41+
return currentPageIndex
42+
}
43+
44+
var debug = false
45+
46+
func SetDebug(option bool) {
47+
debug = option
48+
}
49+
50+
func GetDebug() bool {
51+
return debug
52+
}
53+
54+
func LoadEvent(sport string, games []Event) {
55+
debug := GetDebug()
56+
57+
if len(GetLoadedEvents(sport)) == 0 {
58+
if debug {
59+
fmt.Printf("[%s] Add loaded events for %s", time.Now(), sport)
60+
fmt.Println()
61+
}
62+
AddLoadedEvent(sport, games)
63+
}
64+
}

slides/boxing.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ import (
99
"strings"
1010

1111
"github.com/dos-2/oddshub/models"
12+
"github.com/dos-2/oddshub/sports"
1213

1314
"github.com/rivo/tview"
1415
)
1516

1617
// Boxing creates a slide for boxing odds.
17-
func Boxing(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
18+
func Boxing(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1819
var builder strings.Builder
19-
builder.WriteString("Commencement Date|Ranking|Players|Bookmaker|Spread|Money|Total\n")
20+
headerString := "Commencement Date|Ranking|Players|Bookmaker|Spread –|Money –|Total –\n"
21+
22+
models.LoadEvent(string(sports.Boxing), games)
2023

2124
for _, game := range games {
2225
builder.WriteString(FormatTeamEvent(game))
2326
}
2427

25-
return "Boxing", GetHeader(models.Boxing), CreateH2HTable("Boxing", builder.String())
28+
return "Boxing", GetHeader(models.Boxing), CreateH2HTable(pages, "Boxing", headerString, games)
2629
}

slides/brazil_campeonato_soccer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

15-
func BrazilCampeonato(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
16+
func BrazilCampeonato(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1617
var builder strings.Builder
17-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
18+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
19+
20+
models.LoadEvent(string(sports.Soccer_brazil_campeonato), games)
1821

1922
for _, game := range games {
2023
builder.WriteString(FormatTeamEvent(game))
2124
}
2225

23-
return "Brazil Campeonato", GetHeader(models.Soccer_brazil_campeonato), CreateH2HTable(string(models.Soccer_brazil_campeonato), builder.String())
26+
return "Brazil Campeonato", GetHeader(models.Soccer_brazil_campeonato), CreateH2HTable(pages, string(models.Soccer_brazil_campeonato), headerString, games)
2427
}

slides/copa_america_soccer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

15-
func CopaAmericaSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
16+
func CopaAmericaSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1617
var builder strings.Builder
17-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
18+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
19+
20+
models.LoadEvent(string(sports.Soccer_conmebol_copa_america), games)
1821

1922
for _, game := range games {
2023
builder.WriteString(FormatTeamEvent(game))
2124
}
2225

23-
return "Copa America", GetHeader(models.Soccer_conmebol_copa_america), CreateH2HTable(string(models.Soccer_conmebol_copa_america), builder.String())
26+
return "Copa America", GetHeader(models.Soccer_conmebol_copa_america), CreateH2HTable(pages, string(models.Soccer_conmebol_copa_america), headerString, games)
2427
}

slides/cover.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const (
3333
)
3434

3535
// Cover returns the cover page.
36-
func Cover(games []models.Event, nextSlide func()) (title string, header string, content tview.Primitive) {
36+
func Cover(pages *tview.Pages, games []models.Event) (title string, header string, content tview.Primitive) {
3737
// What's the size of the logo?
3838
lines := strings.Split(logo, "\n")
3939
logoWidth := 0
@@ -44,10 +44,7 @@ func Cover(games []models.Event, nextSlide func()) (title string, header string,
4444
}
4545
}
4646
logoBox := tview.NewTextView().
47-
SetTextColor(tcell.NewRGBColor(57, 255, 20)).
48-
SetDoneFunc(func(key tcell.Key) {
49-
nextSlide()
50-
})
47+
SetTextColor(tcell.NewRGBColor(57, 255, 20))
5148
fmt.Fprint(logoBox, logo)
5249

5350
// Create a frame for the subtitle and navigation infos.

slides/epl_soccer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

15-
func EPLSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
16+
func EPLSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1617
var builder strings.Builder
17-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
18+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
19+
20+
models.LoadEvent(string(sports.Soccer_epl), games)
1821

1922
for _, game := range games {
2023
builder.WriteString(FormatTeamEvent(game))
2124
}
2225

23-
return "EPL Soccer", GetHeader(models.Soccer_epl), CreateH2HTable(string(models.Soccer_epl), builder.String())
26+
return "EPL Soccer", GetHeader(models.Soccer_epl), CreateH2HTable(pages, string(models.Soccer_epl), headerString, games)
2427
}

slides/ipl_cricket.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

1516
// IPLCricket creates a slide for IPL cricket odds.
16-
func IPLCricket(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17+
func IPLCricket(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1718
var builder strings.Builder
18-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
19+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
20+
21+
models.LoadEvent(string(sports.Cricket_ipl), games)
1922

2023
for _, game := range games {
2124
builder.WriteString(FormatTeamEvent(game))
2225
}
2326

24-
return "IPL", GetHeader(models.Cricket_ipl), CreateH2HTable(string(models.Cricket_ipl), builder.String())
27+
return "IPL", GetHeader(models.Cricket_ipl), CreateH2HTable(pages, string(models.Cricket_ipl), headerString, games)
2528
}

slides/la_liga_soccer.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@
55
package slides
66

77
import (
8-
"strings"
9-
108
"github.com/dos-2/oddshub/models"
9+
"github.com/dos-2/oddshub/sports"
1110

1211
"github.com/rivo/tview"
1312
)
1413

1514
// LaLigaSoccer creates a slide for La Liga soccer odds.
16-
func LaLigaSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17-
var builder strings.Builder
18-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
15+
func LaLigaSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
16+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
1917

20-
for _, game := range games {
21-
builder.WriteString(FormatTeamEvent(game))
22-
}
18+
models.LoadEvent(string(sports.Soccer_spain_la_liga), games)
2319

24-
return "La Liga", GetHeader(models.Soccer_spain_la_liga), CreateH2HTable(string(models.Soccer_spain_la_liga), builder.String())
20+
return "La Liga", GetHeader(models.Soccer_spain_la_liga), CreateH2HTable(pages, string(models.Soccer_spain_la_liga), headerString, games)
2521
}

slides/masters_golf.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@
55
package slides
66

77
import (
8-
"strings"
9-
108
"github.com/dos-2/oddshub/models"
9+
"github.com/dos-2/oddshub/sports"
1110

1211
"github.com/rivo/tview"
1312
)
1413

1514
// MastersGolf creates a slide for golf odds.
16-
func MastersGolf(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17-
var builder strings.Builder
18-
builder.WriteString("Commencement Date|Teams|Players|Bookmaker|Outrights||\n")
15+
func MastersGolf(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
16+
headerString := "Commencement Date|Teams|Players|Bookmaker|Outrights||\n"
1917

20-
if len(games) > 0 {
21-
builder.WriteString(FormatTournamentEvent(games[0]))
22-
}
18+
models.LoadEvent(string(sports.Golf_masters_tournament_winner), games)
2319

24-
return "Masters", GetHeader(models.Golf_masters_tournament_winner), CreateRoundRobinTable(string(models.Golf_masters_tournament_winner), builder.String())
20+
return "Masters", GetHeader(models.Golf_masters_tournament_winner), CreateRoundRobinTable(string(models.Golf_masters_tournament_winner), headerString, games)
2521
}

slides/mens_french_open_tennis.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

1516
// FrenchOpenTennis creates a slide for tennis odds.
16-
func MensFrenchOpenTennis(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17+
func MensFrenchOpenTennis(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1718
var builder strings.Builder
18-
builder.WriteString("Commencement Date|Location|Players|Bookmaker|Spread|Money|Total\n")
19+
headerString := "Commencement Date|Location|Players|Bookmaker|Spread –|Money –|Total –\n"
20+
21+
models.LoadEvent(string(sports.Tennis_atp_french_open), games)
1922

2023
for _, game := range games {
2124
builder.WriteString(FormatTeamEvent(game))
2225
}
2326

24-
return "Mens French Open", GetHeader(models.Tennis_atp_french_open), CreateH2HTable("Mens French Open Tennis", builder.String())
27+
return "Mens French Open", GetHeader(models.Tennis_atp_french_open), CreateH2HTable(pages, "Mens French Open Tennis", headerString, games)
2528
}

slides/mens_wimbledon_tennis.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

15-
func MensWimbledonTennis(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
16+
func MensWimbledonTennis(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1617
var builder strings.Builder
17-
builder.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
18+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
19+
20+
models.LoadEvent(string(sports.Tennis_atp_wimbledon), games)
1821

1922
for _, game := range games {
2023
builder.WriteString(FormatTeamEvent(game))
2124
}
2225

23-
return "Wimbledon", GetHeader(models.Tennis_atp_wimbledon), CreateH2HTable(string(models.Tennis_atp_wimbledon), builder.String())
26+
return "Wimbledon", GetHeader(models.Tennis_atp_wimbledon), CreateH2HTable(pages, string(models.Tennis_atp_wimbledon), headerString, games)
2427
}

slides/mlb_baseball.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

1516
// MLBBaseball creates a slide for baseball odds.
16-
func MLBBaseball(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17+
func MLBBaseball(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1718
var tableData strings.Builder
18-
tableData.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
19+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
20+
21+
models.LoadEvent(string(sports.Baseball_mlb), games)
1922

2023
for _, game := range games {
2124
tableData.WriteString(FormatTeamEvent(game))
2225
}
2326

24-
return "MLB", GetHeader(models.Baseball_mlb), CreateH2HTable("MLB Baseball", tableData.String())
27+
return "MLB", GetHeader(models.Baseball_mlb), CreateH2HTable(pages, "MLB Baseball", headerString, games)
2528
}

slides/mls_soccer.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import (
88
"strings"
99

1010
"github.com/dos-2/oddshub/models"
11+
"github.com/dos-2/oddshub/sports"
1112

1213
"github.com/rivo/tview"
1314
)
1415

1516
// MLSSoccer creates a slide for soccer odds.
16-
func MLSSoccer(games []models.Event, nextSlide func()) (string, string, tview.Primitive) {
17+
func MLSSoccer(pages *tview.Pages, games []models.Event) (string, string, tview.Primitive) {
1718
var tableData strings.Builder
18-
tableData.WriteString("Commencement Date|Location|Teams|Bookmaker|Spread|Money|Total\n")
19+
headerString := "Commencement Date|Location|Teams|Bookmaker|Spread –|Money –|Total –\n"
20+
21+
models.LoadEvent(string(sports.Soccer_usa_mls), games)
1922

2023
for _, game := range games {
2124
tableData.WriteString(FormatTeamEvent(game))
2225
}
2326

24-
return "MLS", GetHeader(models.Soccer_usa_mls), CreateH2HTable("MLS Soccer", tableData.String())
27+
return "MLS", GetHeader(models.Soccer_usa_mls), CreateH2HTable(pages, "MLS Soccer", headerString, games)
2528
}

0 commit comments

Comments
 (0)