api_authentication.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import boto3, json, praw
  2. from spotipy import util
  3. def get_aws_secret(secret_name, region):
  4. # Retrieve the AWS secret from secret manager to use in below
  5. # authentication function
  6. session = boto3.session.Session()
  7. client = session.client(
  8. service_name='secretsmanager',
  9. region_name=region)
  10. get_secret_value_response = client.get_secret_value(SecretId=secret_name)
  11. secret_data = get_secret_value_response['SecretString']
  12. secret_data = json.loads(secret_data)
  13. return secret_data
  14. def reddit_obj(client_id, client_secret, user):
  15. # Create a reddit object to make API calls with
  16. user_agent = f"script:hotPlaylistGenerator:v01.0 (by u/{user}"
  17. reddit = praw.Reddit(
  18. client_id=client_id,
  19. client_secret=client_secret,
  20. user_agent=user_agent)
  21. return reddit
  22. def spotify_auth(client_id, client_secret, user):
  23. # spotify credential jazz for their API
  24. #parameters in request for access token
  25. redirect_uri = "https://localhost:8080"
  26. scope = "playlist-modify-public"
  27. # token generation
  28. token = util.prompt_for_user_token(
  29. username=user,
  30. scope=scope,
  31. client_id=client_id,
  32. client_secret=client_secret,
  33. redirect_uri=redirect_uri)
  34. return token
  35. def sql_db():
  36. # connect to sql db
  37. return