diff --git a/README.md b/README.md index 27f3431..ff54fc6 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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") diff --git a/assets/img/haas_dashboard.png b/assets/img/haas_dashboard.png new file mode 100644 index 0000000..947e73d Binary files /dev/null and b/assets/img/haas_dashboard.png differ diff --git a/assets/img/haas_notification.jpeg b/assets/img/haas_notification.jpeg new file mode 100644 index 0000000..62a2d4d Binary files /dev/null and b/assets/img/haas_notification.jpeg differ diff --git a/checker.go b/checker.go index c59f6ef..4360ff3 100644 --- a/checker.go +++ b/checker.go @@ -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) diff --git a/event-item.go b/event-item.go index c1ad4a9..531a71a 100644 --- a/event-item.go +++ b/event-item.go @@ -52,6 +52,12 @@ func (e UnitedEventItem) State() string { return "unavailable" } + _, err := e.FindBuyButton() + + if err != nil { + return "unavailable" + } + return "available" } diff --git a/event-list-page.go b/event-list-page.go index 6580cbc..7a718b9 100644 --- a/event-list-page.go +++ b/event-list-page.go @@ -8,9 +8,9 @@ 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{ @@ -18,13 +18,12 @@ func (c *UnitedEventListPage) FindAvailableEvents(premier_league_only bool) []*U 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 }