summaryrefslogtreecommitdiff
path: root/server/potd.py
blob: 3732ef47b4a9db7087c8c3fa27a3f1948ba6b4bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3
import requests
from xml.etree import ElementTree
from getfeaturedpictures import get_urls_of_images
from urllib.parse import unquote

headers = {'Accept-Encoding':'gzip', 'User-Agent': 'contact pommicket+jigsaw @ gmail.com '}

URL = 'https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=rss&maxlag=5'

response = requests.get(URL, headers=headers).text
xml = ElementTree.fromstring(response)
item = xml.findall('channel/item')[-1]
desc = item.find('description').text
start = desc.index('"/wiki/File:') + len('"/wiki/')
end = desc.index('"', start)
name = unquote(desc[start:end])
url = get_urls_of_images([name])[0]
print(url)