| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import json |
| 5 |
import re |
| 6 |
import sys |
| 7 |
import urllib.request |
| 8 |
import xml.etree.ElementTree as ET |
| 9 |
from datetime import datetime |
| 10 |
|
| 11 |
input_data = sys.stdin.read() |
| 12 |
|
| 13 |
tree = ET.fromstring(input_data) |
| 14 |
pattern = re.compile("href=\"(https://[^<>]+\.(gif|png|jpg))\"") |
| 15 |
|
| 16 |
for ite in tree.find("channel").iter("item"): |
| 17 |
link = ite.find("link").text |
| 18 |
|
| 19 |
response = urllib.request.urlopen(link) |
| 20 |
text = response.read().decode("utf-8") |
| 21 |
for pic_link in re.findall(pattern, text): |
| 22 |
new = ET.SubElement(ite, "enclosure") |
| 23 |
new.set("url", pic_link[0]) |
| 24 |
new.set("type", "image/" + pic_link[1]) |
| 25 |
|
| 26 |
|
| 27 |
print(ET.tostring(tree, encoding="unicode")) |