mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-14 07:04:27 -04:00
Add support for Pinboard RSS feeds
This commit is contained in:
parent
05adc74c69
commit
b5c6d34860
1 changed files with 30 additions and 0 deletions
30
parse.py
30
parse.py
|
@ -17,6 +17,7 @@ Parsed link schema: {
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
import xml.etree.ElementTree as etree
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -36,6 +37,7 @@ def get_parsers(file):
|
||||||
'pinboard': parse_json_export,
|
'pinboard': parse_json_export,
|
||||||
'bookmarks': parse_bookmarks_export,
|
'bookmarks': parse_bookmarks_export,
|
||||||
'rss': parse_rss_export,
|
'rss': parse_rss_export,
|
||||||
|
'pinboard_rss': parse_pinboard_rss_feed,
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_links(path):
|
def parse_links(path):
|
||||||
|
@ -169,3 +171,31 @@ def parse_bookmarks_export(html_file):
|
||||||
info['type'] = get_link_type(info)
|
info['type'] = get_link_type(info)
|
||||||
|
|
||||||
yield info
|
yield info
|
||||||
|
|
||||||
|
def parse_pinboard_rss_feed(rss_file):
|
||||||
|
"""Parse Pinboard RSS feed files into links"""
|
||||||
|
|
||||||
|
rss_file.seek(0)
|
||||||
|
root = etree.parse(rss_file).getroot()
|
||||||
|
items = root.findall("{http://purl.org/rss/1.0/}item")
|
||||||
|
for item in items:
|
||||||
|
url = item.find("{http://purl.org/rss/1.0/}link").text
|
||||||
|
tags = item.find("{http://purl.org/dc/elements/1.1/}subject").text
|
||||||
|
title = item.find("{http://purl.org/rss/1.0/}title").text
|
||||||
|
ts_str = item.find("{http://purl.org/dc/elements/1.1/}date").text
|
||||||
|
# Pinboard includes a colon in its date stamp timezone offsets, which
|
||||||
|
# Python can't parse. Remove it:
|
||||||
|
if ":" == ts_str[-3:-2]:
|
||||||
|
ts_str = ts_str[:-3]+ts_str[-2:]
|
||||||
|
time = datetime.strptime(ts_str, "%Y-%m-%dT%H:%M:%S%z")
|
||||||
|
info = {
|
||||||
|
'url': url,
|
||||||
|
'domain': domain(url),
|
||||||
|
'base_url': base_url(url),
|
||||||
|
'timestamp': str(time.timestamp()),
|
||||||
|
'tags': tags,
|
||||||
|
'title': title,
|
||||||
|
'sources': [rss_file.name],
|
||||||
|
}
|
||||||
|
info['type'] = get_link_type(info)
|
||||||
|
yield info
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue