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 os
import sys
import requests
import importlib
import logging
@ -9,7 +8,6 @@ import settings
import time
import croniter
def main():
config = settings.load_settings()
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 tomlkit
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():
general = tomlkit.table()

View File

@ -1,6 +1,7 @@
import datetime
import logging
import re
import time
from providers._provider import Provider
# https://api.wikimedia.org/wiki/Feed_API/Reference/Featured_content
@ -13,6 +14,8 @@ class Wikimedia(Provider):
super().__init__(settings, session)
def get_image_info(self):
# Since wikipedia API seems to fail to provide image url, we will retry on key error until we get the image url
try:
today = datetime.datetime.now()
date = today.strftime('%Y/%m/%d')
logging.debug(f"Date: {date}")
@ -27,5 +30,8 @@ class Wikimedia(Provider):
image_url = image
title = response['image']['description']['text']
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"
croniter = "^5.0"
[tool.poetry.scripts]
daily-wallpaper = "app.daily_wallpaper:__main__"
[build-system]
requires = ["poetry-core"]