clean up a bit
This commit is contained in:
parent
90dc4b78f1
commit
303219dfb1
@ -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)
|
@ -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()
|
@ -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,19 +14,24 @@ class Wikimedia(Provider):
|
||||
super().__init__(settings, session)
|
||||
|
||||
def get_image_info(self):
|
||||
today = datetime.datetime.now()
|
||||
date = today.strftime('%Y/%m/%d')
|
||||
logging.debug(f"Date: {date}")
|
||||
url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' + date
|
||||
logging.debug(f"URL: {url}")
|
||||
# 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}")
|
||||
url = 'https://api.wikimedia.org/feed/v1/wikipedia/en/featured/' + date
|
||||
logging.debug(f"URL: {url}")
|
||||
|
||||
response = self.session.get(url).json()
|
||||
# logging.debug(f"Response: {response}")
|
||||
response = self.session.get(url).json()
|
||||
# logging.debug(f"Response: {response}")
|
||||
|
||||
image = response['image']['image']['source']
|
||||
logging.debug(f"Image: {image}")
|
||||
image_url = image
|
||||
image = response['image']['image']['source']
|
||||
logging.debug(f"Image: {image}")
|
||||
image_url = image
|
||||
|
||||
title = response['image']['description']['text']
|
||||
|
||||
return image_url, title
|
||||
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()
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user