public
Last active

short python script to save your google reader data to couchdb.

  • Download Gist
reader_to_couchdb.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#!/usr/bin/python2
 
import logging
import sys
import couchdb
import json
from libgreader import GoogleReader, ClientAuthMethod, Feed
 
"""
Original can be obtained here: https://gist.github.com/Nazgolze/5479539
Released to the public domain.
"""
 
db_name = "YOUR DB NAME GOES HERE"
username = "YOUR USERNAME GOES HERE"
password = "YOUR PASSWORD GOES HERE"
 
def loadUntilSuccessful(subscription, load):
try:
subscription.loadItems(loadLimit=load)
except Exception:
logging.warning(sys.exc_info()[0])
print "Continuing..."
sys.exc_clear()
loadUntilSuccessful(subscription, load)
 
def loadMoreUntilSuccessful(subscription, load):
try:
subscription.items = []
subscription.itemsById = {}
subscription.loadMoreItems(loadLimit=load)
except Exception:
logging.warning(sys.exc_info()[0])
print "Continuing..."
sys.exc_clear()
loadMoreUntilSuccessful(subscription, load)
 
couch = couchdb.Server('http://localhost:5984')
try:
db = couch[db_name]
except Exception:
db = couch.create(db_name)
auth = ClientAuthMethod(username, password)
reader = GoogleReader(auth)
ll = 100
reader.buildSubscriptionList()
l = reader.getSubscriptionList()
 
for li in l:
print li.title.encode('ascii', 'xmlcharrefreplace')
loadUntilSuccessful(li, ll)
while li.lastLoadLength > 0:
bulk_upload = []
for i in li.getItems():
doc = {}
doc = i.data
if len(li.categories) > 0:
doc["label"] = li.categories[0].label
bulk_upload.append(doc)
db.update(bulk_upload)
loadMoreUntilSuccessful(li, ll)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.