| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import json |
| 7 |
import sys |
| 8 |
import urllib.request |
| 9 |
import xml.etree.ElementTree as ET |
| 10 |
|
| 11 |
|
| 12 |
atom_ns = {"atom": "http://www.w3.org/2005/Atom"} |
| 13 |
|
| 14 |
def main(): |
| 15 |
sys.stdin.reconfigure(encoding="utf-8") |
| 16 |
feed_data = sys.stdin.read() |
| 17 |
feed_document = ET.fromstring(feed_data) |
| 18 |
|
| 19 |
|
| 20 |
elem_title = feed_document.find("atom:title", atom_ns) |
| 21 |
elem_description = feed_document.find("atom:subtitle", atom_ns) |
| 22 |
elem_title = feed_document.find("atom:title", atom_ns) |
| 23 |
elem_icon = ET.SubElement(feed_document, ET.QName(atom_ns["atom"], "icon")) |
| 24 |
|
| 25 |
|
| 26 |
channel_id = feed_document.find(".//atom:uri", atom_ns).text |
| 27 |
channel_id = channel_id[channel_id.index("channel/") + 8:] |
| 28 |
|
| 29 |
|
| 30 |
api_url = "https://pipedapi.kavin.rocks/channel/{}".format(channel_id) |
| 31 |
api_request = urllib.request.Request(api_url) |
| 32 |
|
| 33 |
api_request.add_header("User-Agent", "curl") |
| 34 |
api_response = urllib.request.urlopen(api_request) |
| 35 |
api_data = api_response.read().decode("utf-8") |
| 36 |
|
| 37 |
|
| 38 |
api_json = json.loads(api_data) |
| 39 |
elem_title.text = api_json["name"] |
| 40 |
elem_description.text = api_json["description"] |
| 41 |
elem_icon.text = api_json["avatarUrl"] |
| 42 |
|
| 43 |
print(ET.tostring(feed_document).decode()) |
| 44 |
|
| 45 |
if __name__ == '__main__': |
| 46 |
main() |