Skip to content

Instantly share code, notes, and snippets.

@goerz
Last active December 15, 2015 08:09
Show Gist options
  • Save goerz/5228468 to your computer and use it in GitHub Desktop.
Save goerz/5228468 to your computer and use it in GitHub Desktop.
Script for importing Google Reader starred items (from starred.json file obtained from Google Checkout) into Pinboard. The import on the Pinboard website didn't work for me.
#!/usr/bin/env python
import json
from html2text import html2text
import pinboard
import time
import sys
username = 'pinboardusername'
password = 'secret'
def get_summary(item):
summary = item['origin']['title'] + ": "
try:
summary += html2text(item['summary']['content'])
except KeyError:
return item['origin']['title']
if len(summary) > 10000:
summary = summary[0:10000] + '...'
return summary
def get_tags(item):
tags = []
for tag in item['categories']:
if not tag.startswith('user/'):
tag = tag.replace(" ", "_")
tags.append(tag)
tags.append('GReader')
return tags
def get_date(item):
seconds = item['published']
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(seconds))
def greader_to_pinboard_dataset(item):
url = item['alternate'][0]['href']
description = item['title']
extended = get_summary(item)
tags = get_tags(item)
date = get_date(item)
return (url, description, extended, tags, date)
def main():
file = open("starred.json")
greader_data = json.load(file)
pinboard_datasets = []
for item in greader_data['items']:
pinboard_datasets.append(greader_to_pinboard_dataset(item))
pb = pinboard.connect(username, password)
i = 0
for (url, description, extended, tags, date) in pinboard_datasets:
print "Item %i" % i
pb.add(url, description, extended, tags, date)
print(url, description, extended, tags, date)
i += 1
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment