-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialise.go
53 lines (50 loc) · 1.13 KB
/
initialise.go
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
package main
import (
"github.com/simonmartyr/toogoodtogogo"
"log"
"net/http"
)
func Initialise(username string) {
client := toogoodtogo.New(
&http.Client{},
toogoodtogo.WithUsername(username),
)
authErr := client.Authenticate()
if authErr != nil {
log.Fatal(authErr)
return
}
log.Println("Authentication successful, creating config")
favorites, getErr := client.GetFavorites(0, 0, 500, 0, 50)
if getErr != nil {
log.Fatal(getErr)
return
}
var favList []Item
for _, x := range favorites.MobileBucket.Items {
favList = append(favList, Item{
Name: x.DisplayName,
ItemName: x.Item.Name,
ItemId: x.Item.ItemId,
Notify: true,
LastNotified: "",
})
}
credentials := client.GetCredentials()
config := Config{
EmailConfig: EmailConfig{
To: username,
Account: "gmail",
},
Credentials: TooGoodToGoCredentials{
UserId: credentials.UserId,
Email: username,
AccessToken: credentials.AccessToken,
RefreshToken: credentials.RefreshToken,
Cookie: credentials.Cookie,
},
Items: favList,
}
config.WriteConfig()
log.Println("Config created")
}