Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (81 loc) · 2.31 KB
/
Copy pathmain.go
File metadata and controls
91 lines (81 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"context"
"log"
"log/slog"
"os"
"time"
"github.com/ahobsonsayers/twigots"
"github.com/ahobsonsayers/twigots/filter"
"github.com/ahobsonsayers/twigots/keys"
)
func main() {
keysURL := os.Getenv("TWICKETS_KEYS_URL")
if keysURL == "" {
log.Fatal("TWICKETS_KEYS_URL is not set")
}
twicketsKeys, err := keys.FromURL(keysURL)
if err != nil {
log.Fatal(err)
}
// Create twickets client
client, err := twigots.NewClient(twicketsKeys)
if err != nil {
log.Fatal(err)
}
// Fetch ticket listings
listings, err := client.FetchTicketListings(
context.Background(),
twigots.FetchTicketListingsInput{
// Required
Country: twigots.CountryUnitedKingdom, // Only UK is supported at the moment
// Optional. See all options in godoc
CreatedBefore: time.Now(),
CreatedAfter: time.Now().Add(time.Duration(-5 * time.Minute)), // 5 mins ago
MaxNumber: 100,
},
)
if err != nil {
log.Fatal(err)
}
log.Printf("Fetched %d ticket listings", len(listings))
// Filter ticket listings just by name
// Use the default event name similarity (0.9) to allow minor mismatches
hamiltonListings := filter.FilterTicketListings(
listings,
filter.EventName("Hamilton", filter.DefaultEventNameSimilarity),
)
for idx := 0; idx < len(hamiltonListings); idx++ {
listing := listings[idx]
slog.Info(
"Found Hamilton ticket listing",
"Event", listing.Event.Name,
"NumTickets", listing.NumTickets,
"Price", listing.TotalPriceInclFee().String(),
"OriginalPrice", listing.OriginalTicketPrice().String(),
"URL", listing.URL(),
)
}
// Filter ticket listings just by several filters
coldplayListings := filter.FilterTicketListings(
listings,
filter.EventName("Coldplay", 1), // Event name similarity of 1 - exact match only
filter.EventRegion( // Only in specific regions
twigots.RegionLondon,
twigots.RegionSouth,
),
filter.NumTickets(2), // Exactly 2 tickets in the listing
filter.MinDiscount(0.1), // Discount of > 10%
)
for idx := 0; idx < len(coldplayListings); idx++ {
listing := coldplayListings[idx]
slog.Info(
"Found Coldplay ticket listing",
"Event", listing.Event.Name,
"NumTickets", listing.NumTickets,
"Price", listing.TotalPriceInclFee().String(),
"OriginalPrice", listing.OriginalTicketPrice().String(),
"URL", listing.URL(),
)
}
}