Last active
August 29, 2015 14:21
-
-
Save atbradley/57780a4a1fd9437145e5 to your computer and use it in GitHub Desktop.
Read one or more RSS feeds and add the entry links to Pinboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import feedparser | |
import yaml | |
import pinboard | |
from time import mktime | |
import os | |
class RssToPinboard(object): | |
def __init__(self, settings): | |
here = os.path.dirname(os.path.realpath(__file__)) | |
self.settings_file = os.path.join(here, settings) | |
with open(self.settings_file, 'r') as f: | |
settings = yaml.load(f) | |
self.settings = settings | |
self.pb = pinboard.Pinboard(settings['pinboard_token']) | |
def __enter__(self): | |
return self | |
def __exit__(self, e_type, e_val, tb): | |
with open(self.settings_file, 'w') as f: | |
yaml.dump(self.settings, f, default_flow_style=False) | |
def run(self): | |
for f in self.settings['feeds']: | |
feed = feedparser.parse(f['url']) | |
toread = f.get('toread', False) | |
entries = feed['entries'] | |
if f.get('last'): | |
entries = [e for e in entries if mktime(e['published_parsed']) > f.get('last')] | |
#Save the date of the most recent entry. | |
if entries: | |
f['last'] = mktime(max([e['published_parsed'] for e in entries])) | |
for entry in entries: | |
try: | |
self.pb.posts.add(url=entry['link'], description=entry['title'], toread=toread) | |
except: | |
pass | |
with RssToPinboard('.feedstopinboard.settings.yml') as rtp: | |
rtp.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feeds: | |
- toread: true | |
url: https://www.instapaper.com/rss/13007/abcdefghijklmnop | |
- toread: true | |
url: http://someotherfeed.com/?rss=saved | |
pinboard_token: someone:1234567890abcdef |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment