Skip to content

Commit

Permalink
instagram scraping: add 'scrape' constructor kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Mar 30, 2016
1 parent b8b08cb commit b0e6443
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions activitystreams.py
Expand Up @@ -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())
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions granary/instagram.py
Expand Up @@ -59,7 +59,7 @@ class Instagram(source.Source):
</blockquote>
"""

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.
Expand All @@ -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."""
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b0e6443

Please sign in to comment.