Created
July 4, 2012 11:48
-
-
Save key/3046945 to your computer and use it in GitHub Desktop.
Fetch all feeds from Google Reader
This file contains 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
# coding:utf-8 | |
# please install gdata module from pypi | |
import gdata.service | |
FEED_URL = 'http://example.com/feed' | |
# google account | |
CONFIG = { | |
'Email': '[email protected]', | |
'Passwd': 'yourpasswordhere' | |
} | |
counter = 0 | |
def request(service, continuation=''): | |
params = { | |
'n': '500', | |
'c': continuation | |
} | |
query = gdata.service.Query(feed='/reader/atom/feed/%s' % FEED_URL, params=params) | |
feed = service.Get(query.ToUri()) | |
return feed | |
def build_text(feed): | |
global counter | |
for entry in feed.entry: | |
fp = open("%s.txt" % counter, 'w') | |
fp.write("""href: %s | |
title: %s | |
body: | |
%s | |
""" % (entry.GetHtmlLink().href, entry.title.text, entry.summary.text)) | |
fp.close() | |
counter += 1 | |
def main(): | |
# Google Reader service setting | |
service = gdata.service.GDataService(account_type='GOOGLE', | |
service='reader', | |
server='www.google.com', | |
) | |
# Google login | |
service.ClientLogin(CONFIG['Email'], CONFIG['Passwd']) | |
feed = None | |
while True: | |
continuation = '' | |
if feed: | |
try: | |
continuation = feed.extension_elements[0].text | |
except IndexError: | |
break | |
feed = request(service, continuation) | |
build_text(feed) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment