Skip to content

Instantly share code, notes, and snippets.

@ewancook
Last active June 10, 2019 17:07
Show Gist options
  • Save ewancook/f3749be04a6eebddefcd24658318c984 to your computer and use it in GitHub Desktop.
Save ewancook/f3749be04a6eebddefcd24658318c984 to your computer and use it in GitHub Desktop.
fixr: buying crisis tickets
package main
import (
"fmt"
"math/rand"
"time"
"github.com/ewancook/fixr"
"github.com/howeyc/gopass"
)
type ticket struct {
event, index, amount int
}
func main() {
fixr.UpdateVersion()
email := "email@email.com"
list := []ticket{ticket{event: 478304484, index: 2, amount: 4},
ticket{event: 341126298, index: 2, amount: 3},
ticket{event: 928770982, index: 2, amount: 3}}
// Setting up timers
buyTime := "2018-04-02 16:00:02"
loc, err := time.LoadLocation("Europe/London")
if err != nil {
fmt.Printf("(%s) Error parsing location (for time): %v\n", email, err)
return
}
dur, err := time.ParseInLocation("2006-01-02 15:04:05", buyTime, loc)
if err != nil {
fmt.Printf("(%s) Error parsing time: %v\n", email, dur)
return
}
left := time.Until(dur)
if left.Seconds() < -60*10 {
fmt.Printf("(%s) No point running this now!\n", email)
return
}
buyTimer := time.NewTimer(left)
// Login/Time to buy!
fmt.Printf("(%s) Please enter your FIXR password: ", email)
password, err := gopass.GetPasswdMasked()
if err != nil {
fmt.Printf("(%s) Error occurred when inputting password.\n", email)
return
}
c := fixr.NewClient(email)
if err := c.Logon(string(password)); err != nil {
fmt.Printf("(%s) %v\n", email, err)
return
}
fmt.Printf("(%s) Logged in!\n", email)
card, err := c.HasCard()
if err != nil {
fmt.Printf("(%s) %v\n", email, err)
}
if !card {
fmt.Printf("(%s) No payment method: add a card at http://fixr.co\n", email)
return
}
for _, l := range list {
fmt.Printf("(%s) Added %d tickets to queue (%d: %d)\n", email, l.amount, l.event, l.index)
}
fmt.Printf("(%s) Waiting for %.0f seconds\n", email, left.Seconds())
<-buyTimer.C
// Buy tickets!
for _, t := range list {
e, err := c.Event(t.event)
if err != nil {
fmt.Printf("(%s) Couldn't buy ticket (%d: %d): %v\n", email, t.event, t.index, err)
continue
}
if p, err := c.Book(&e.Tickets[t.index], t.amount, nil); err != nil {
fmt.Printf("(%s) Couldn't buy ticket (%d: %d): %v\n", email, t.event, t.index, err)
} else {
fmt.Printf("(%s) Bought ticket (%s) PDF: %s\n", email, e.Tickets[t.index].Name, p.PDF)
}
<-time.NewTimer(time.Duration(5+rand.Intn(4)) * time.Second).C
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment