mirror of
https://github.com/agresdominik/predictify.git
synced 2026-04-21 17:55:49 +00:00
Fixed doc
This commit is contained in:
+11
-11
@@ -1,16 +1,16 @@
|
|||||||
import dotenv
|
|
||||||
import time
|
|
||||||
from urllib.parse import urlencode, urlparse, parse_qs
|
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
||||||
import requests
|
|
||||||
import os
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
from urllib.parse import parse_qs, urlencode, urlparse
|
||||||
|
|
||||||
|
import dotenv
|
||||||
|
import requests
|
||||||
|
|
||||||
TOKEN_FILE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'env', 'tokens.json')
|
TOKEN_FILE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'env', 'tokens.json')
|
||||||
|
|
||||||
|
|
||||||
def authenticate(scope: str) -> tuple:
|
def authenticate(scope: str) -> str:
|
||||||
"""
|
"""
|
||||||
This function authenticates the user and returns the access token
|
This function authenticates the user and returns the access token
|
||||||
|
|
||||||
@@ -29,14 +29,14 @@ def authenticate(scope: str) -> tuple:
|
|||||||
access_token, refresh_token = _refresh_access_token(refresh_token, spotify_client_id, spotify_client_secret)
|
access_token, refresh_token = _refresh_access_token(refresh_token, spotify_client_id, spotify_client_secret)
|
||||||
_save_tokens(access_token, refresh_token)
|
_save_tokens(access_token, refresh_token)
|
||||||
return access_token
|
return access_token
|
||||||
|
|
||||||
auth_url = _get_authorization_url(spotify_client_id, spotify_redirect_uri, scope)
|
auth_url = _get_authorization_url(spotify_client_id, spotify_redirect_uri, scope)
|
||||||
print(f'Please go to the following URL to authorize the app: {auth_url}')
|
print(f'Please go to the following URL to authorize the app: {auth_url}')
|
||||||
|
|
||||||
authorization_code = _start_server_and_wait_for_code()
|
authorization_code = _start_server_and_wait_for_code()
|
||||||
|
|
||||||
access_token, refresh_token = _exchange_code_for_token(authorization_code, redirect_uri=spotify_redirect_uri,
|
access_token, refresh_token = _exchange_code_for_token(authorization_code, redirect_uri=spotify_redirect_uri,
|
||||||
client_id=spotify_client_id, client_secret=spotify_client_secret)
|
client_id=spotify_client_id, client_secret=spotify_client_secret)
|
||||||
|
|
||||||
_save_tokens(access_token, refresh_token)
|
_save_tokens(access_token, refresh_token)
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ def _start_server_and_wait_for_code() -> any:
|
|||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(b"Authorization successful! You can close this window.")
|
self.wfile.write(b"Authorization successful! You can close this window.")
|
||||||
|
|
||||||
server = HTTPServer(('localhost', 8888), CallbackHandler)
|
server = HTTPServer(('localhost', 8888), CallbackHandler)
|
||||||
print("Starting server to capture the authorization code...")
|
print("Starting server to capture the authorization code...")
|
||||||
server.handle_request()
|
server.handle_request()
|
||||||
@@ -200,4 +200,4 @@ def _save_tokens(access_token: str, refresh_token: str) -> None:
|
|||||||
'expires_at': expires_at
|
'expires_at': expires_at
|
||||||
}
|
}
|
||||||
with open(TOKEN_FILE_PATH, 'w') as f:
|
with open(TOKEN_FILE_PATH, 'w') as f:
|
||||||
json.dump(tokens, f)
|
json.dump(tokens, f)
|
||||||
|
|||||||
Reference in New Issue
Block a user