__package__ = 'archivebox.parsers'
from typing import IO, Iterable
from datetime import datetime
from ..index.schema import Link
from ..util import (
htmldecode,
enforce_types,
str_between,
)
@enforce_types
def parse_generic_rss_export(rss_file: IO[str], **_kwargs) -> Iterable[Link]:
"""Parse RSS XML-format files into links"""
rss_file.seek(0)
items = rss_file.read().split('- ')
items = items[1:] if items else []
for item in items:
# example item:
#
-
#
# Unread
# https://blog.sessionstack.com/how-javascript-works-inside
# https://blog.sessionstack.com/how-javascript-works-inside
# Mon, 21 Aug 2017 14:21:58 -0500
#
trailing_removed = item.split(' ', 1)[0]
leading_removed = trailing_removed.split('- ', 1)[-1].strip()
rows = leading_removed.split('\n')
def get_row(key):
return [r for r in rows if r.strip().startswith('<{}>'.format(key))][0]
url = str_between(get_row('link'), '', '')
ts_str = str_between(get_row('pubDate'), '', '')
time = datetime.strptime(ts_str, "%a, %d %b %Y %H:%M:%S %z")
title = str_between(get_row('title'), '