1
0
Fork 0
mirror of synced 2024-06-11 15:04:38 +12:00
ArchiveBox/archivebox/parsers/pinboard_rss.py

49 lines
1.2 KiB
Python
Raw Normal View History

2019-04-28 09:26:24 +12:00
__package__ = 'archivebox.parsers'
from typing import IO, Iterable
from time import mktime
from feedparser import parse as feedparser
2019-04-28 09:26:24 +12:00
from ..index.schema import Link
from ..util import (
htmldecode,
enforce_types
2019-04-28 09:26:24 +12:00
)
@enforce_types
def parse_pinboard_rss_export(rss_file: IO[str], **_kwargs) -> Iterable[Link]:
2019-04-28 09:26:24 +12:00
"""Parse Pinboard RSS feed files into links"""
rss_file.seek(0)
feed = feedparser(rss_file.read())
for item in feed.entries:
url = item.link
# title will start with "[priv] " if pin was marked private. useful?
title = item.title
time = mktime(item.updated_parsed)
# all tags are in one entry.tags with spaces in it. annoying!
try:
tags = item.tags[0].term.replace(' ', ',')
except AttributeError:
tags = ''
2019-04-28 09:26:24 +12:00
if url is None:
# Yielding a Link with no URL will
# crash on a URL validation assertion
continue
2019-04-28 09:26:24 +12:00
yield Link(
url=htmldecode(url),
timestamp=str(time),
2019-04-28 09:26:24 +12:00
title=htmldecode(title) or None,
tags=htmldecode(tags) or None,
sources=[rss_file.name],
)
KEY = 'pinboard_rss'
NAME = 'Pinboard RSS'
PARSER = parse_pinboard_rss_export