Skip to content

Commit

Permalink
feat: adds more unavailable matches and imrpoves readme
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertYoung committed Sep 24, 2022
1 parent 6d3bb3c commit 17bdcbb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

A application to scrape the Manchested United ticket site to find available matches, prices, and pushes the data to Home Assistant.

## Getting Started
## Installation

- Download the latest release from [Github](https://github.com/RobertYoung/manutd-ticket-checker/releases/latest)

## Usage

```sh
# run application
> go run .
> ./manutd-ticket-checker

# only show premier league matches
> go run . --premier-league-only
> ./manutd-ticket-checker --premier-league-only

# push state to home assistant and send notification
> go run . --premier-league-only --haas-url ${HA_URL} --haas-token ${HA_TOKEN}
> ./manutd-ticket-checker --premier-league-only --haas-url ${HA_URL} --haas-token ${HA_TOKEN}

# optionally, a file can be specified to configure the cli
> go run . --env-file env.yml
> ./manutd-ticket-checker --env-file env.yml

# cli usage
> go run . -h
> ./manutd-ticket-checker -h
NAME:
manutd-ticket-checker - finds available manchester united tickets

Expand All @@ -37,3 +41,18 @@ GLOBAL OPTIONS:
--premier-league-only, --plo (default: false)
--rod value rod specific arguments, eg. https://go-rod.github.io/#/get-started/README?id=slow-motion-and-visual-trace
```

## Development

```sh
# run application
> go run .

# create a snapshot with goreleaser
> goreleaser release --snapshot --rm-dist
```

## Home Assistsant

![Home Assistant Dashboard Example](/assets/img/haas_dashboard.png "Home Assistant Dashboard Example")
![Home Assistant Notification Example](/assets/img/haas_notification.jpeg "Home Assistant Notification Example")
Binary file added assets/img/haas_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/haas_notification.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ func (c *UnitedChecker) Check() {
c.browser = rod.New()
c.LoadEventListPage()
c.event_list.DeleteCookieOverlay()
c.available_events = c.event_list.FindAvailableEvents(c.premier_league_only)
c.available_events = c.event_list.FindEvents(c.premier_league_only)

for _, event := range c.available_events {
_, err := event.FindBuyButton()

if err != nil {
continue
}

name := event.Name()
log.Printf("checking %s...", name)

Expand Down
6 changes: 6 additions & 0 deletions event-item.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ func (e UnitedEventItem) State() string {
return "unavailable"
}

_, err := e.FindBuyButton()

if err != nil {
return "unavailable"
}

return "available"
}

Expand Down
11 changes: 5 additions & 6 deletions event-list-page.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@ type UnitedEventListPage struct {
haas_api *haas.HomeAssistantAPI
}

func (c *UnitedEventListPage) FindAvailableEvents(premier_league_only bool) []*UnitedEventItem {
func (c *UnitedEventListPage) FindEvents(premier_league_only bool) []*UnitedEventItem {
events := c.MustElements("#eventsList .dataItem")
var availableEvents []*UnitedEventItem
var event_list []*UnitedEventItem

for _, element := range events {
event := UnitedEventItem{
Element: element,
haas_api: c.haas_api,
}

_, err := event.FindBuyButton()
is_premier_league := premier_league_only && event.IsPremierLeagueEvent()

if err == nil && (!premier_league_only || premier_league_only && is_premier_league) {
availableEvents = append(availableEvents, &event)
if !premier_league_only || premier_league_only && is_premier_league {
event_list = append(event_list, &event)
}
}

return availableEvents
return event_list
}

0 comments on commit 17bdcbb

Please sign in to comment.