diff options
| author | 2019-01-29 22:46:00 +0000 | |
|---|---|---|
| committer | 2019-01-29 22:46:00 +0000 | |
| commit | 9491a44295fd168845744683a72f67b2fc1fb68c (patch) | |
| tree | a91510e1501415fba4f076fe0c2db7c71c3c8aaa /modules/spotify.py | |
| parent | Typo, `{,}` instead of `{:}` made `headers` a set (spotify.py) (diff) | |
| signature | ||
Correctly compare current time and token expire time and actually cache the
token (spotify.py)
Diffstat (limited to 'modules/spotify.py')
| -rw-r--r-- | modules/spotify.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/modules/spotify.py b/modules/spotify.py index e6d819f6..22e44336 100644 --- a/modules/spotify.py +++ b/modules/spotify.py @@ -13,7 +13,7 @@ class Module(ModuleManager.BaseModule): self._token_expires = None def _get_token(self): - if self._token and (self._token_expires+10) < time.time(): + if self._token and time.time() < (self._token_expires+10): return self._token else: client_id = self.bot.config["spotify-client-id"] @@ -25,8 +25,11 @@ class Module(ModuleManager.BaseModule): headers={"Authorization": "Basic %s" % bearer}, post_data={"grant_type": "client_credentials"}, json=True) - self._token_expire = time.time()+page.data["expires_in"] - return page.data["access_token"] + + token = page.data["access_token"] + self._token = token + self._token_expires = time.time()+page.data["expires_in"] + return token @utils.hook("received.command.spotify", min_args=1) def spotify(self, event): |
