From b0e6443f244c4f27b5fd96df1c61304f3095a26d Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Tue, 29 Mar 2016 22:59:20 -0700 Subject: [PATCH] instagram scraping: add 'scrape' constructor kwarg --- activitystreams.py | 5 +---- granary/instagram.py | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/activitystreams.py b/activitystreams.py index d76b8281..fb2e9f55 100644 --- a/activitystreams.py +++ b/activitystreams.py @@ -94,7 +94,7 @@ def get(self): access_token_key=util.get_required_param(self, 'access_token_key'), access_token_secret=util.get_required_param(self, 'access_token_secret')) elif site == 'instagram': - src = instagram.Instagram() + src = instagram.Instagram(scrape=True) elif site == 'google+': auth_entity = util.get_required_param(self, 'auth_entity') src = googleplus.GooglePlus(auth_entity=ndb.Key(urlsafe=auth_entity).get()) @@ -193,9 +193,6 @@ def get_kwargs(self, source): if search_query: kwargs['search_query'] = search_query - if isinstance(source, instagram.Instagram): - kwargs['scrape'] = True - return kwargs def get_positive_int(self, param): diff --git a/granary/instagram.py b/granary/instagram.py index f58de46f..bbf472da 100644 --- a/granary/instagram.py +++ b/granary/instagram.py @@ -59,7 +59,7 @@ class Instagram(source.Source): """ - def __init__(self, access_token=None, allow_comment_creation=False): + def __init__(self, access_token=None, allow_comment_creation=False, scrape=False): """Constructor. If an OAuth access token is provided, it will be passed on to Instagram. @@ -70,9 +70,12 @@ def __init__(self, access_token=None, allow_comment_creation=False): access_token: string, optional OAuth access token allow_comment_creation: boolean, optionally disable comment creation, useful if the app is not approved to create comments. + scrape: boolean, whether to scrape instagram.com's HTML (True) or use + the API (False) """ self.access_token = access_token self.allow_comment_creation = allow_comment_creation + self.scrape = scrape def urlopen(self, url, **kwargs): """Wraps urllib2.urlopen() and passes through the access token.""" @@ -138,7 +141,7 @@ def get_activities_response(self, user_id=None, group_id=None, app_id=None, Raises: InstagramAPIError """ - if scrape: + if scrape or self.scrape: if not ((group_id == source.SELF and (user_id or activity_id)) or (group_id == source.FRIENDS and cookie)): raise NotImplementedError(