clean up a bit

This commit is contained in:
Isaac Shoebottom 2024-11-20 18:56:19 -04:00
parent 90dc4b78f1
commit 303219dfb1
4 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,5 @@
import datetime import datetime
import os import os
import sys
import requests import requests
import importlib import importlib
import logging import logging
@ -9,7 +8,6 @@ import settings
import time import time
import croniter import croniter
def main(): def main():
config = settings.load_settings() config = settings.load_settings()
logging.basicConfig(level=config['general']['log_level'], format="%(asctime)s [%(levelname)s] %(message)s", force=True) logging.basicConfig(level=config['general']['log_level'], format="%(asctime)s [%(levelname)s] %(message)s", force=True)

View File

@ -1,9 +1,8 @@
import logging
import os.path import os.path
import tomlkit import tomlkit
local_path = os.path.abspath("config.toml") local_path = os.path.abspath("config.toml")
user_path = os.path.expanduser("~/.config/daily-wallpaper/config.toml") user_path = os.path.expanduser("~/.config/app/config.toml")
def default_settings(): def default_settings():
general = tomlkit.table() general = tomlkit.table()

View File

@ -1,6 +1,7 @@
import datetime import datetime
import logging import logging
import re import time
from providers._provider import Provider from providers._provider import Provider
# https://api.wikimedia.org/wiki/Feed_API/Reference/Featured_content # https://api.wikimedia.org/wiki/Feed_API/Reference/Featured_content
@ -13,19 +14,24 @@ class Wikimedia(Provider):
super().__init__(settings, session) super().__init__(settings, session)
def get_image_info(self): def get_image_info(self):
today = datetime.datetime.now() # Since wikipedia API seems to fail to provide image url, we will retry on key error until we get the image url
date = today.strftime('%Y/%m/%d') try:
logging.debug(f"Date: {date}") today = datetime.datetime.now()
url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' + date date = today.strftime('%Y/%m/%d')
logging.debug(f"URL: {url}") logging.debug(f"Date: {date}")
url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' + date
logging.debug(f"URL: {url}")
response = self.session.get(url).json() response = self.session.get(url).json()
# logging.debug(f"Response: {response}") # logging.debug(f"Response: {response}")
image = response['image']['image']['source'] image = response['image']['image']['source']
logging.debug(f"Image: {image}") logging.debug(f"Image: {image}")
image_url = image image_url = image
title = response['image']['description']['text'] title = response['image']['description']['text']
return image_url, title
return image_url, title except KeyError:
logging.error("KeyError, retrying...")
time.sleep(10) # Wait 10 seconds
return self.get_image_info()

View File

@ -13,6 +13,9 @@ python-slugify = "^8.0"
tomlkit = "^0.13.2" tomlkit = "^0.13.2"
croniter = "^5.0" croniter = "^5.0"
[tool.poetry.scripts]
daily-wallpaper = "app.daily_wallpaper:__main__"
[build-system] [build-system]
requires = ["poetry-core"] requires = ["poetry-core"]