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