From d6a713a9488d9d3204e9a1374b808b8775179349 Mon Sep 17 00:00:00 2001 From: Parker Date: Sat, 20 Jul 2024 19:02:11 -0500 Subject: Automatically retrieve Apple Music media API key --- code/bot.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'code/bot.py') diff --git a/code/bot.py b/code/bot.py index aafeb0d..2864e85 100644 --- a/code/bot.py +++ b/code/bot.py @@ -6,6 +6,7 @@ import openai import utils.config as config from utils.command_tree import Tree +from utils.media_api_key import get_media_api_key class MyBot(commands.Bot): @@ -19,6 +20,7 @@ class MyBot(commands.Bot): async def setup_hook(self): get_access_token.start() + refresh_media_api_key.start() config.LOG.info("Loading cogs...") for ext in os.listdir("./code/cogs"): if ext.endswith(".py"): @@ -59,6 +61,18 @@ async def get_access_token(): bot.spotify_headers = {"Authorization": f"Bearer {access_token}"} +@tasks.loop(hours=24) +async def refresh_media_api_key(): + media_api_key = get_media_api_key() + if media_api_key is not None: + bot.apple_headers = { + "Authorization": f"Bearer {media_api_key}", + "Origin": "https://apple.com", + } + else: + bot.apple_headers = None + + if __name__ == "__main__": config.load_config() bot.run(config.TOKEN) -- cgit v1.2.3-70-g09d2