aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2020-04-19 11:42:35 +0200
committerneodarz <neodarz@neodarz.net>2020-04-19 11:42:35 +0200
commit84551004407a8c2c3c4a74f30c55b9fc799dc5ae (patch)
tree498983b5bc81c64515516090a54a7de15b6a8148 /README.md
parent2c8fa5251fa49bd8f7e537fbdbc801bc7bc04e59 (diff)
downloadpyfunkwhale-84551004407a8c2c3c4a74f30c55b9fc799dc5ae.tar.xz
pyfunkwhale-84551004407a8c2c3c4a74f30c55b9fc799dc5ae.zip
Move the invalidity token management system outsite of the module
Diffstat (limited to '')
-rw-r--r--README.md18
1 files changed, 16 insertions, 2 deletions
diff --git a/README.md b/README.md
index 023c872..8175cd4 100644
--- a/README.md
+++ b/README.md
@@ -54,16 +54,30 @@ token_endpoint = "https://demo.funkwhale.audio/api/v1/oauth/token/"
# Save the OAuth2 infos in file, this is ugly yup
token_filename = 'oauth_token.data'
+# You need to handle the invalidity of a token and ask for a new one
+def _ask_new_auth(funkwhale, message):
+ print(message)
+ authorization_code = input("Enter response code: ")
+ funkwhale.client._set_token(authorization_code)
+
funkwhale = Funkwhale(client_name, redirect_uri, client_id, client_secret,
scopes, username, password, domain, authorization_endpoint,
token_endpoint, token_filename)
-artists = funkwhale.artists()
+try:
+ artists = funkwhale.artists()
+except InvalidTokenError as e
+ _ask_new_auth(funkwhale, e.message)
+ artists = funkwhale.artists()
print(artists)
# In case you ask, their is an example for downloading a song
-r = funkwhale.listen("f9d02c64-bafa-43cb-8e1e-fa612e7c5dab")
+try:
+ r = funkwhale.listen("f9d02c64-bafa-43cb-8e1e-fa612e7c5dab")
+except InvalidTokenError as e:
+ _ask_new_auth(funkwhale, e.message)
+ r = funkwhale.rate_limit()
with open('/tmp/test.mp3', 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):