diff --git a/cmd/watcher/main.go b/cmd/watcher/main.go index 7f5d462..f0475b6 100644 --- a/cmd/watcher/main.go +++ b/cmd/watcher/main.go @@ -18,6 +18,7 @@ type flags struct { ticketmasterConfigFile string discordWebhookURL string diffMode bool + diffFile string } func main() { @@ -38,7 +39,8 @@ func main() { } reader := ticketmaster.NewReader(f.apiKey) - watcher := watcher.NewWatcher(reader, f.ticketmasterConfigFile, artists, f.discordWebhookURL) + watcher := watcher.NewWatcher(reader, f.ticketmasterConfigFile, artists, + f.discordWebhookURL, f.diffFile) events, err := watcher.FindEvents(f.diffMode) if err != nil { log.Fatalf("Error retrieving events: %v", err) @@ -68,9 +70,10 @@ func parseFlags() *flags { flag.StringVar(&f.discordWebhookURL, "discordWebhookURL", "", "Discord webhook URL") flag.StringVar(&f.ticketmasterConfigFile, "ticketmasterConfig", "ticketmaster.yaml", "Path to a file containing search criteria for ticketmaster event lookups") - flag.BoolVar(&f.diffMode, "diff", false, fmt.Sprintf("Run in diff mode which only notifies "+ - "for events we haven't already seen. Notification history is stored in the %q file "+ - "between runs", watcher.DIFF_FILE)) + flag.BoolVar(&f.diffMode, "diff", false, "Run in diff mode which only notifies "+ + "for events we haven't already seen.") + flag.StringVar(&f.diffFile, "diffFile", "previous-ids", "Path to a file that stores the list "+ + "of events that we have previously sent notifications for") flag.Parse() return f } diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index 433fdfa..f0167d2 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -13,22 +13,22 @@ import ( "github.com/RyanConnell/concert-watcher/pkg/ticketmaster" ) -const DIFF_FILE = "previous-event-ids" - type Watcher struct { ticketmasterAPI ticketmaster.API ticketmasterConfigFile string trackedArtists *set.Set[string] discordWebhookURL string + diffFile string } func NewWatcher(ticketmasterAPI ticketmaster.API, ticketmasterConfigFile string, - trackedArtists []string, discordWebhookURL string) *Watcher { + trackedArtists []string, discordWebhookURL string, diffFile string) *Watcher { return &Watcher{ ticketmasterAPI: ticketmasterAPI, ticketmasterConfigFile: ticketmasterConfigFile, trackedArtists: set.New(trackedArtists...), discordWebhookURL: discordWebhookURL, + diffFile: diffFile, } } @@ -126,7 +126,7 @@ func (w *Watcher) Notify(events []*ticketmaster.Event) error { // Query for a list of events that we've previously notiied on. func (w *Watcher) previousEventIDs() ([]string, error) { - file, err := os.Open(DIFF_FILE) + file, err := os.Open(w.diffFile) if errors.Is(err, fs.ErrNotExist) { return nil, nil } @@ -145,7 +145,7 @@ func (w *Watcher) previousEventIDs() ([]string, error) { // Save seen event IDs so that we don't send duplicate notifications each time we run. func (w *Watcher) saveEventIDs(ids []string) error { - file, err := os.Create(DIFF_FILE) + file, err := os.Create(w.diffFile) if err != nil { return err }