def main(): auth = OAuthMethod(oauth_key, oauth_secret) auth.setRequestToken() print auth.buildAuthUrl() raw_input() auth.setAccessToken() reader = GoogleReader(auth) print reader.getUserInfo()
def test_full_auth_process_without_callback(self): auth = OAuthMethod(oauth_key, oauth_secret) auth.setRequestToken() auth_url = auth.buildAuthUrl() response = automated_oauth_approval(auth_url) auth.setAccessToken() reader = GoogleReader(auth) info = reader.getUserInfo() self.assertEqual(dict, type(info)) self.assertEqual(firstname, info['userName'])
def test_full_auth_and_access_userdata(self): auth = OAuth2Method(client_id, client_secret) auth.setRedirectUri(redirect_url) url = auth.buildAuthUrl() token = automated_oauth2_approval(url) auth.code = token auth.setAccessToken() reader = GoogleReader(auth) info = reader.getUserInfo() self.assertEqual(dict, type(info)) self.assertEqual(firstname, info['userName'])
def test_full_auth_process_with_callback(self): auth = OAuthMethod(oauth_key, oauth_secret) #must be a working callback url for testing auth.setCallback("http://www.asktherelic.com") token, token_secret = auth.setAndGetRequestToken() auth_url = auth.buildAuthUrl() #callback section #get response, which is a redirect to the callback url response = automated_oauth_approval(auth_url) query_string = urlparse.urlparse(response.geturl()).query #grab the verifier token from the callback url query string token_verifier = urlparse.parse_qs(query_string)['oauth_verifier'][0] auth.setAccessTokenFromCallback(token, token_secret, token_verifier) reader = GoogleReader(auth) info = reader.getUserInfo() self.assertEqual(dict, type(info)) self.assertEqual(firstname, info['userName'])
def test_reader_user_info(self): ca = ClientAuthMethod(username,password) reader = GoogleReader(ca) info = reader.getUserInfo() self.assertEqual(dict, type(info)) self.assertEqual(firstname, info['userName'])
def import_google_reader_begin(user_id, access_token): auth = OAuth2Method(settings.GOOGLE_OAUTH2_CLIENT_ID, settings.GOOGLE_OAUTH2_CLIENT_SECRET) auth.authFromAccessToken(access_token) reader = GoogleReader(auth) django_user, mongo_user = get_user_from_dbs(user_id) username = django_user.username try: user_infos = reader.getUserInfo() except TypeError: LOGGER.exception(u'Could not start Google Reader import for user %s.', username) # Don't refresh, it's now done by a dedicated periodic task. # If we failed, it means the problem is quite serious. # import_google_reader_trigger(user_id, refresh=True) return GR_MAX_FEEDS = config.GR_MAX_FEEDS LOGGER.info(u'Starting Google Reader import for user %s.', username) gri = GoogleReaderImport(user_id) # take note of user informations now that we have them. gri.start(user_infos=user_infos) reader.buildSubscriptionList() total_reads, reg_date = reader.totalReadItems(without_date=False) total_starred, star1_date = reader.totalStarredItems(without_date=False) total_feeds = len(reader.feeds) + 1 # +1 for 'starred' gri.reg_date(pytime.mktime(reg_date.timetuple())) gri.star1_date(pytime.mktime(star1_date.timetuple())) gri.total_reads(total_reads) gri.total_starred(total_starred) LOGGER.info( u'Google Reader import for user %s: %s feed(s) and %s read ' u'article(s) to go…', username, total_feeds, total_reads) if total_feeds > GR_MAX_FEEDS and not settings.DEBUG: mail_admins( 'User {0} has more than {1} feeds: {2}!'.format( username, GR_MAX_FEEDS, total_feeds), u"\n\nThe GR import will be incomplete.\n\n" u"Just for you to know…\n\n") # We launch the starred feed import first. Launching it after the # standard feeds makes it being delayed until the world's end. reader.makeSpecialFeeds() starred_feed = reader.getSpecialFeed(ReaderUrl.STARRED_LIST) import_google_reader_starred.apply_async((user_id, username, starred_feed), queue='low') processed_feeds = 1 feeds_to_import = [] for gr_feed in reader.feeds[:GR_MAX_FEEDS]: try: feed = create_feed(gr_feed, mongo_user) except Feed.DoesNotExist: LOGGER.exception( u'Could not create feed “%s” for user %s, ' u'skipped.', gr_feed.title, username) continue processed_feeds += 1 feeds_to_import.append((user_id, username, gr_feed, feed)) LOGGER.info(u'Imported feed “%s” (%s/%s) for user %s…', gr_feed.title, processed_feeds, total_feeds, username) # We need to clamp the total, else task won't finish in # the case where the user has more feeds than allowed. # gri.total_feeds(min(processed_feeds, GR_MAX_FEEDS)) for feed_args in feeds_to_import: import_google_reader_articles.apply_async(feed_args, queue='low') LOGGER.info( u'Imported %s/%s feeds in %s. Articles import already ' u'started with limits: date: %s, %s waves of %s articles, ' u'max articles: %s, reads: %s, starred: %s.', processed_feeds, total_feeds, naturaldelta(now() - gri.start()), naturaltime(max([gri.reg_date(), GR_OLDEST_DATE])), config.GR_WAVE_LIMIT, config.GR_LOAD_LIMIT, config.GR_MAX_ARTICLES, total_reads, total_starred)
from libgreader import GoogleReader, ClientAuthMethod username = "******" password = "******" ca = ClientAuthMethod(username, password) reader = GoogleReader(ca) info = reader.getUserInfo() print info x = reader.buildSubscriptionList() if x == "True": print ("Subscription list built.") else: print ("Something went wrong with building the subscription list.") print ("Printing feed objects...") print reader.feeds # reader.feeds is a list, so we can play around wtih individual objects print reader.feeds[0] # Each list item has some properties associated with it print reader.feeds[0].id print reader.feeds[0].title # List comprehension for returning feed id print [x.id for x in reader.feeds]
from libgreader import GoogleReader, ClientAuthMethod, Feed auth = ClientAuthMethod('acpigeon', 'Katana666') reader = GoogleReader(auth) print reader.getUserInfo()
def import_google_reader_begin(user_id, access_token): auth = OAuth2Method(settings.GOOGLE_OAUTH2_CLIENT_ID, settings.GOOGLE_OAUTH2_CLIENT_SECRET) auth.authFromAccessToken(access_token) reader = GoogleReader(auth) django_user, mongo_user = get_user_from_dbs(user_id) username = django_user.username try: user_infos = reader.getUserInfo() except TypeError: LOGGER.exception(u'Could not start Google Reader import for user %s.', username) # Don't refresh, it's now done by a dedicated periodic task. # If we failed, it means the problem is quite serious. # import_google_reader_trigger(user_id, refresh=True) return GR_MAX_FEEDS = config.GR_MAX_FEEDS LOGGER.info(u'Starting Google Reader import for user %s.', username) gri = GoogleReaderImport(user_id) # take note of user informations now that we have them. gri.start(user_infos=user_infos) reader.buildSubscriptionList() total_reads, reg_date = reader.totalReadItems(without_date=False) total_starred, star1_date = reader.totalStarredItems(without_date=False) total_feeds = len(reader.feeds) + 1 # +1 for 'starred' gri.reg_date(pytime.mktime(reg_date.timetuple())) gri.star1_date(pytime.mktime(star1_date.timetuple())) gri.total_reads(total_reads) gri.total_starred(total_starred) LOGGER.info(u'Google Reader import for user %s: %s feed(s) and %s read ' u'article(s) to go…', username, total_feeds, total_reads) if total_feeds > GR_MAX_FEEDS and not settings.DEBUG: mail_admins('User {0} has more than {1} feeds: {2}!'.format( username, GR_MAX_FEEDS, total_feeds), u"\n\nThe GR import will be incomplete.\n\n" u"Just for you to know…\n\n") # We launch the starred feed import first. Launching it after the # standard feeds makes it being delayed until the world's end. reader.makeSpecialFeeds() starred_feed = reader.getSpecialFeed(ReaderUrl.STARRED_LIST) import_google_reader_starred.apply_async((user_id, username, starred_feed), queue='low') processed_feeds = 1 feeds_to_import = [] for gr_feed in reader.feeds[:GR_MAX_FEEDS]: try: feed = create_feed(gr_feed, mongo_user) except Feed.DoesNotExist: LOGGER.exception(u'Could not create feed “%s” for user %s, ' u'skipped.', gr_feed.title, username) continue processed_feeds += 1 feeds_to_import.append((user_id, username, gr_feed, feed)) LOGGER.info(u'Imported feed “%s” (%s/%s) for user %s…', gr_feed.title, processed_feeds, total_feeds, username) # We need to clamp the total, else task won't finish in # the case where the user has more feeds than allowed. # gri.total_feeds(min(processed_feeds, GR_MAX_FEEDS)) for feed_args in feeds_to_import: import_google_reader_articles.apply_async(feed_args, queue='low') LOGGER.info(u'Imported %s/%s feeds in %s. Articles import already ' u'started with limits: date: %s, %s waves of %s articles, ' u'max articles: %s, reads: %s, starred: %s.', processed_feeds, total_feeds, naturaldelta(now() - gri.start()), naturaltime(max([gri.reg_date(), GR_OLDEST_DATE])), config.GR_WAVE_LIMIT, config.GR_LOAD_LIMIT, config.GR_MAX_ARTICLES, total_reads, total_starred)