Skip to content

Commit

Permalink
de-dupe Facebook photos and posts of those photos. fixes #127
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Apr 14, 2014
1 parent 3f05754 commit 419fb1d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activitystreams
10 changes: 9 additions & 1 deletion facebook.py
Expand Up @@ -139,7 +139,15 @@ def get_activities_response(self, **kwargs):
raise

items = resp.setdefault('items', [])
items += [self.as_source.post_to_activity(p) for p in photos]

# only add photos that we don't already have activities for
fb_object_ids = util.trim_nulls(set(
i.get('object', {}).get('fb_object_id') for i in items))
logging.info('@ %s %s', fb_object_ids,
[p.get('id') for p in photos])
items += [self.as_source.post_to_activity(p) for p in photos
if p.get('id') not in fb_object_ids]

items += [self.as_source.event_to_activity(e, rsvps=r)
for e, r in events_and_rsvps]
return resp
Expand Down
15 changes: 15 additions & 0 deletions facebook_test.py
Expand Up @@ -79,6 +79,21 @@ def test_get_activities(self):
event_activity,
], page.get_activities())

def test_get_activities_post_and_photo_duplicates(self):
self.expect_urlopen(
'https://graph.facebook.com/me/posts?offset=0&access_token=my_token',
json.dumps({'data': [as_facebook_test.POST]}))
self.expect_urlopen(
'https://graph.facebook.com/me/photos/uploaded?access_token=my_token',
json.dumps({'data': [as_facebook_test.PHOTO]}))
self.expect_urlopen(
'https://graph.facebook.com/me/events?access_token=my_token',
json.dumps({}))
self.mox.ReplayAll()

page = FacebookPage.new(self.handler, auth_entity=self.auth_entity)
self.assert_equals([as_facebook_test.ACTIVITY], page.get_activities())

def test_revoked(self):
self.expect_urlopen(
'https://graph.facebook.com/me/posts?offset=0&access_token=my_token',
Expand Down

0 comments on commit 419fb1d

Please sign in to comment.