From cf73b4eda97680dfb988abb8eb6dad64670187db Mon Sep 17 00:00:00 2001 From: Dalton Williams Date: Sat, 5 Oct 2024 10:18:30 -0500 Subject: [PATCH] Offseason increased rate limit, closes #41 --- internal/api/api.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index b185926..3d7f7f1 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -19,7 +19,8 @@ const YEAR_URL = BASE_URL + "/%v" const DAY_URL = YEAR_URL + "/day/%v" // Number of API requests allowed per second. -const REQS_PER_SEC = 10 +const ONSEASON_REQS_PER_SEC = 10 +const OFFSEASON_REQS_PER_SEC = 25 var MasterClient httpClient @@ -46,7 +47,14 @@ func (c *httpClient) Do(req *http.Request) (*http.Response, error) { // InitClient creates the API client with a given user session token. func InitClient(userSessionToken string) { - limiter := rate.NewLimiter(rate.Every(time.Second/REQS_PER_SEC), 1) + var reqsPerSec int + if time.Now().Month() <= time.October && time.Now().Month() >= time.March { + reqsPerSec = OFFSEASON_REQS_PER_SEC + } else { + reqsPerSec = ONSEASON_REQS_PER_SEC + } + + limiter := rate.NewLimiter(rate.Every(time.Second/time.Duration(reqsPerSec)), 1) client := httpClient{ client: http.Client{}, sessionToken: userSessionToken,