forked from Yifan-Song793/RestGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_spotify.py
38 lines (27 loc) · 1.05 KB
/
init_spotify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import json
import logging
import yaml
import spotipy.util as util
from langchain_community.utilities import TextRequestsWrapper
from utils import init_spotify
logger = logging.getLogger()
def main():
config = yaml.load(open("config.yaml", "r"), Loader=yaml.FullLoader)
os.environ["OPENAI_API_KEY"] = config["openai_api_key"]
os.environ["SPOTIPY_CLIENT_ID"] = config["spotipy_client_id"]
os.environ["SPOTIPY_CLIENT_SECRET"] = config["spotipy_client_secret"]
os.environ["SPOTIPY_REDIRECT_URI"] = config["spotipy_redirect_uri"]
with open("specs/spotify_oas.json") as f:
raw_api_spec = json.load(f)
scopes = list(
raw_api_spec["components"]["securitySchemes"]["oauth_2_0"]["flows"][
"authorizationCode"
]["scopes"].keys()
)
access_token = util.prompt_for_user_token(scope=",".join(scopes))
headers = {"Authorization": f"Bearer {access_token}"}
requests_wrapper = TextRequestsWrapper(headers=headers)
init_spotify(requests_wrapper)
if __name__ == "__main__":
main()