Skip to content

Commit

Permalink
Fixed showing profile link icon for TBD team (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vuon9 authored Mar 18, 2023
1 parent aadf996 commit b97002d
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 183 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Dota2 scheduled matches tracker

![Main](./screenshots/main.gif)
![Main](./screenshots/main-with-details.gif)

## Installation

Expand All @@ -25,7 +25,7 @@ Or download the binary from [release page](https://github.com/vuon9/d2m/releases
❯ d2m
```

## Key features
## Features
- Filter matches by time, status:
- Upcoming
- Live
Expand All @@ -34,11 +34,10 @@ Or download the binary from [release page](https://github.com/vuon9/d2m/releases
- Today
- Yesterday
- From today
- View details of teams
- Open Twitch streaming link in browser

## Tasks

- Async handle for the details, to ensure can handle async call well
- make a call to a function which has sleep 3, return text when end
- handle loading during the sleeping time
- show the returned text
- Some display icons to help you quickly identify the status:
- Team has info: ◆
- Team has no info: ◇
- Live match has streaming page: ▶
- Live match has no streaming page: ▷
63 changes: 60 additions & 3 deletions cmd/d2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"log"
"os"

"github.com/vuon9/d2m/internal/app"
"github.com/urfave/cli/v2"
iapp "github.com/vuon9/d2m/internal/app"
"github.com/vuon9/d2m/pkg/api/liquipedia"
)

func Execute() {
prog := app.NewApp()
prog.Run(context.Background())
app := &cli.App{
Name: "d2m",
Action: func(*cli.Context) error {
prog := iapp.NewApp()
return prog.Run(context.Background())
},
Commands: []*cli.Command{
{
Name: "test",
Subcommands: []*cli.Command{
{
Name: "list",
Action: func(cCtx *cli.Context) error {
client := liquipedia.NewClient()
matches, err := client.GetScheduledMatches(cCtx.Context)
if err != nil {
return err
}

for i, m := range matches {
log.Printf("%d. %s vs %s", i+1, m.Team1().TeamProfileLink, m.Team2().TeamProfileLink)
}

return nil
},
},
{
Name: "details",
Action: func(cCtx *cli.Context) error {
client := liquipedia.NewClient()
team, err := client.GetTeamDetailsPage(cCtx.Context, "https://liquipedia.net/dota2/OG")
if err != nil {
return err
}

bTeam, err := json.MarshalIndent(team, "", " ")
if err != nil {
return err
}

fmt.Println(string(bTeam))

return nil
},
},
},
},
},
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/gocolly/colly v1.2.0
github.com/samber/lo v1.37.0
github.com/urfave/cli/v2 v2.25.0
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
golang.org/x/sync v0.1.0 // indirect
)
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/charmbracelet/lipgloss v0.6.0 h1:1StyZB9vBSOyuZxQUcUwGr17JmojPNm87ini
github.com/charmbracelet/lipgloss v0.6.0/go.mod h1:tHh2wr34xcHjC2HCXIlGSG1jaDF0S0atAUvBMP6Ppuk=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
Expand Down Expand Up @@ -68,6 +70,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
Expand All @@ -79,6 +83,10 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg=
github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo=
github.com/urfave/cli/v2 v2.25.0 h1:ykdZKuQey2zq0yin/l7JOm9Mh+pg72ngYMeB0ABn6q8=
github.com/urfave/cli/v2 v2.25.0/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down
37 changes: 8 additions & 29 deletions internal/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,29 @@ package app
import (
"context"

"github.com/charmbracelet/bubbles/list"
tea "github.com/charmbracelet/bubbletea"
"github.com/vuon9/d2m/pkg/api"
"github.com/vuon9/d2m/pkg/api/liquipedia"
)

type app struct {
tracker Tracker
}
type App struct{}

type Apper interface {
Run(ctx context.Context) error
func NewApp() *App {
return &App{}
}

func NewApp() Apper {
return &app{
tracker: NewTracker(),
}
}
var apiClient api.Clienter = liquipedia.NewClient()

// RunProgram prints matches as table on terminal
func (a *app) Run(ctx context.Context) error {
matches, err := a.tracker.GetMatches(ctx)
if err != nil {
return err
}

// for _, match := range matches {
// fmt.Println(match.Team1().FullName, match.Team2().FullName, match.Start)
// fmt.Println(match.Team1().TeamProfileLink, match.Team2().TeamProfileLink)
// fmt.Println()
// }

items := make([]list.Item, 0)
for _, match := range matches {
items = append(items, match)
}

func (a *App) Run(ctx context.Context) error {
f, err := tea.LogToFile("debug.log", "debug")
if err != nil {
return err
}

defer f.Close()

prog := tea.NewProgram(newModel(items), tea.WithAltScreen())
prog := tea.NewProgram(newModel(), tea.WithAltScreen())
if _, err := prog.Run(); err != nil {
return err
}
Expand Down
Loading

0 comments on commit b97002d

Please sign in to comment.