1
0
Fork 0

Parse Medium RSS feeds

closes https://github.com/pirate/bookmark-archiver/issues/64
This commit is contained in:
Chris Dzombak 2018-03-13 22:23:52 -04:00
parent b5c6d34860
commit f49f1b5aa0
No known key found for this signature in database
GPG key ID: 394E28F2E5BFE8EF

View file

@ -38,6 +38,7 @@ def get_parsers(file):
'bookmarks': parse_bookmarks_export, 'bookmarks': parse_bookmarks_export,
'rss': parse_rss_export, 'rss': parse_rss_export,
'pinboard_rss': parse_pinboard_rss_feed, 'pinboard_rss': parse_pinboard_rss_feed,
'medium_rss': parse_medium_rss_feed,
} }
def parse_links(path): def parse_links(path):
@ -199,3 +200,28 @@ def parse_pinboard_rss_feed(rss_file):
} }
info['type'] = get_link_type(info) info['type'] = get_link_type(info)
yield info yield info
def parse_medium_rss_feed(rss_file):
"""Parse Medium RSS feed files into links"""
rss_file.seek(0)
root = etree.parse(rss_file).getroot()
items = root.find("channel").findall("item")
for item in items:
for child in item:
print(child.tag, child.text)
url = item.find("link").text
title = item.find("title").text
ts_str = item.find("pubDate").text
time = datetime.strptime(ts_str, "%a, %d %b %Y %H:%M:%S %Z")
info = {
'url': url,
'domain': domain(url),
'base_url': base_url(url),
'timestamp': str(time.timestamp()),
'tags': "",
'title': title,
'sources': [rss_file.name],
}
info['type'] = get_link_type(info)
yield info