Skip to content

Commit

Permalink
instagram (browser extension): implement get_comment()
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 22, 2020
1 parent be8535e commit 87732ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
18 changes: 11 additions & 7 deletions instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ def get_activities_response(self, *args, **kwargs):
return self.gr_source.make_activities_base_response(
[json_loads(a.activity_json) for a in activities])

def get_comment(self, comment_id, **kwargs):
"""Uses the Activity entity stored in the datastore."""
TODO
def get_comment(self, comment_id, activity=None, **kwargs):
"""Uses the activity passed in the activity kwarg."""
if activity:
for reply in activity.get('object', {}).get('replies', {}).get('items', []):
parsed = util.parse_tag_uri(reply.get('id', ''))
if parsed and parsed[1] == comment_id:
return reply

def get_like(self, activity_user_id, activity_id, like_user_id, **kwargs):
def get_like(self, activity_user_id, activity_id, like_user_id, activity=None,
**kwargs):
"""Uses the activity passed in the activity kwarg."""
obj = kwargs.get('activity', {}).get('object')
if obj:
for tag in obj.get('tags', []):
if activity:
for tag in activity.get('object', {}).get('tags', []):
if tag.get('verb') == 'like':
parsed = util.parse_tag_uri(tag.get('author', {}).get('id', ''))
if parsed and parsed[1] == like_user_id:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ def test_get_activities_response_no_stored_activity(self):
resp = self.inst.get_activities_response(activity_id='123')
self.assertEqual([], resp['items'])

def test_get_comment(self):
self.assert_equals(
HTML_VIDEO_EXTRA_COMMENT_OBJ,
self.inst.get_comment('020', activity=HTML_VIDEO_ACTIVITY_FULL))

def test_get_comment_no_matching_id(self):
self.assertIsNone(self.inst.get_comment('333', activity=HTML_VIDEO_ACTIVITY_FULL))

def test_get_comment_no_activity_kwarg(self):
self.assertIsNone(self.inst.get_comment('020'))

def test_get_like(self):
self.assert_equals(LIKE_OBJS[1], self.inst.get_like(
'unused', '123', '9', activity=HTML_PHOTO_ACTIVITY_LIKES))
Expand Down

0 comments on commit 87732ef

Please sign in to comment.