limit requests

master
Martin Thielecke 2 years ago
parent 9f71865570
commit 79f7b617da
Signed by: mthie
GPG Key ID: D1D25A85C8604DFB
  1. 7
      follower.go
  2. 21
      main.go
  3. 13
      settings.go
  4. 5
      subs.go

@ -30,7 +30,7 @@ type TwitchFollower struct {
FollowedAt time.Time `json:"followed_at"`
}
func getFollows(u *User) {
func getFollows(u *User, max int) {
result := &TwitchFollowers{}
after := ""
@ -64,6 +64,11 @@ func getFollows(u *User) {
if t.Pagination == nil || t.Pagination.Cursor == "" {
break
}
if max > -1 && len(result.Data) >= max {
break
}
after = "&after=" + t.Pagination.Cursor
}

@ -48,7 +48,12 @@ func main() {
if user != nil {
handleSaves()
}
c := time.Tick(20 * time.Second)
interval := 20 * time.Second
if settings.UpdateInterval > 10*time.Second {
interval = settings.UpdateInterval
}
log.Infof("Update interval: %s", interval)
c := time.Tick(interval)
for range c {
if user == nil {
continue
@ -77,12 +82,22 @@ func handleSaves() {
user.TwitchChannel.SaveFiles()
}
getFollows(user)
maxFollower := -1
if settings.MaxFollowers > 0 {
maxFollower = settings.MaxFollowers
}
log.Infof("Fetch max follower: %d", maxFollower)
getFollows(user, maxFollower)
if user.TwitchFollowers != nil {
user.TwitchFollowers.SaveFiles()
}
getSubs(user)
maxSubs := -1
if settings.MaxSubs > 0 {
maxSubs = settings.MaxSubs
}
log.Infof("Fetch max subs: %d", maxSubs)
getSubs(user, maxSubs)
if user.TwitchSubscriptions != nil {
user.TwitchSubscriptions.SaveFiles()
}

@ -17,11 +17,14 @@ var (
)
type Settings struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
RedirectURL string `yaml:"redirect_url"`
VerificationToken string `yaml:"verification_token"`
WebserverPort string `yaml:"webserver_port"`
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
MaxFollowers int `yaml:"max_followers"`
MaxSubs int `yaml:"max_subs"`
RedirectURL string `yaml:"redirect_url"`
UpdateInterval time.Duration `yaml:"update_interval"`
VerificationToken string `yaml:"verification_token"`
WebserverPort string `yaml:"webserver_port"`
}
func loadSettings() {

@ -37,7 +37,7 @@ type TwitchSubUser struct {
UpdatedAt time.Time `json:"updated_at"`
}
func getSubs(u *User) {
func getSubs(u *User, max int) {
result := &TwitchSubscriptions{}
limit := 100
@ -74,6 +74,9 @@ func getSubs(u *User) {
result.Total = t.Total
result.Subscriptions = append(result.Subscriptions, t.Subscriptions...)
if max > -1 && len(result.Subscriptions) >= max {
break
}
offset += limit
}

Loading…
Cancel
Save