2019-04-27 21:26:24 +00:00
|
|
|
__package__ = 'archivebox.parsers'
|
|
|
|
|
|
|
|
|
|
|
|
from typing import IO, Iterable
|
2024-02-25 20:34:51 +00:00
|
|
|
from time import mktime
|
|
|
|
from feedparser import parse as feedparser
|
2019-04-27 21:26:24 +00:00
|
|
|
|
|
|
|
from ..index.schema import Link
|
2024-10-01 00:25:15 +00:00
|
|
|
from archivebox.misc.util import (
|
2019-04-27 21:26:24 +00:00
|
|
|
htmldecode,
|
2024-02-25 20:34:51 +00:00
|
|
|
enforce_types
|
2019-04-27 21:26:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@enforce_types
|
2020-08-18 12:27:47 +00:00
|
|
|
def parse_pinboard_rss_export(rss_file: IO[str], **_kwargs) -> Iterable[Link]:
|
2019-04-27 21:26:24 +00:00
|
|
|
"""Parse Pinboard RSS feed files into links"""
|
|
|
|
|
|
|
|
rss_file.seek(0)
|
2024-02-25 20:34:51 +00:00
|
|
|
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-27 21:26:24 +00:00
|
|
|
|
2021-08-04 13:26:51 +00:00
|
|
|
if url is None:
|
|
|
|
# Yielding a Link with no URL will
|
|
|
|
# crash on a URL validation assertion
|
|
|
|
continue
|
|
|
|
|
2019-04-27 21:26:24 +00:00
|
|
|
yield Link(
|
|
|
|
url=htmldecode(url),
|
2024-02-25 20:34:51 +00:00
|
|
|
timestamp=str(time),
|
2019-04-27 21:26:24 +00:00
|
|
|
title=htmldecode(title) or None,
|
|
|
|
tags=htmldecode(tags) or None,
|
|
|
|
sources=[rss_file.name],
|
|
|
|
)
|
2021-03-31 05:05:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
KEY = 'pinboard_rss'
|
|
|
|
NAME = 'Pinboard RSS'
|
|
|
|
PARSER = parse_pinboard_rss_export
|