daily-wallpaper/providers/wikimedia.py

33 lines
804 B
Python
Raw Normal View History

2024-11-20 04:53:04 -04:00
import datetime
import logging
import requests
import re
from providers.provider import Provider
# https://api.wikimedia.org/wiki/Feed_API/Reference/Featured_content
class wikimedia(Provider):
name = "Wikimedia"
url = "https://api.wikimedia.org/feed/v1/wikipedia/en/featured/"
def __init__(self, settings, session):
super().__init__(settings, session)
def get_image_url(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}")
response = self.session.get(url).json()
logging.debug(f"Response: {response}")
image = response['image']['image']['source']
logging.debug(f"Image: {image}")
image_url = image
return image_url