Skip to content

Commit

Permalink
Flickr: add publish support for regular tags
Browse files Browse the repository at this point in the history
somewhat related to #58
and snarfed/bridgy#478
  • Loading branch information
kylewm committed Jan 8, 2016
1 parent 4b3dd8b commit 235faa2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions granary/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def _create(self, obj, preview, include_link, ignore_formatting=False):
image_url = util.get_first(obj, 'image').get('url')
name = obj.get('displayName')
people = self._get_person_tags(obj)
hashtags = [t.get('displayName') for t in obj.get('tags', [])
if t.get('objectType') == 'hashtag' and t.get('displayName')]
lat = obj.get('location', {}).get('latitude')
lng = obj.get('location', {}).get('longitude')

Expand All @@ -151,6 +153,8 @@ def _create(self, obj, preview, include_link, ignore_formatting=False):
preview_content += '<h4>%s</h4>' % name
if content:
preview_content += '<div>%s</div>' % content
if hashtags:
preview_content += '<div> %s</div>' % ' '.join('#' + t for t in hashtags)
if people:
preview_content += '<div> with %s</div>' % ', '.join(
('<a href="%s">%s</a>' % (
Expand All @@ -174,6 +178,14 @@ def _create(self, obj, preview, include_link, ignore_formatting=False):
'type': 'post',
'url': self.photo_url(self.path_alias() or self.user_id(), photo_id),
})

# add regular tags
if hashtags:
self.call_api_method('flickr.photos.addTags', {
'photo_id': photo_id,
'tags': ','.join('"%s"' % t if ' ' in t else t for t in hashtags),
})

# add person tags
for person_id in sorted(p.get('id') for p in people):
self.call_api_method('flickr.photos.people.add', {
Expand Down
14 changes: 14 additions & 0 deletions granary/test/test_flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ def tag_uri(name):
'url': 'https://flickr.com/photos/382@123/',
'displayName': 'Jeena',
'objectType': 'person',
}, {
'displayName': 'indieweb',
'objectType': 'hashtag',
}, {
'displayName': 'homebrew website club',
'objectType': 'hashtag',
}],
'location': {
'objectType': 'place',
Expand Down Expand Up @@ -852,6 +858,8 @@ def test_preview_create_photo(self):
self.assertIn(
'<a href="https://flickr.com/photos/382@123/">Jeena</a>',
preview.content)
# hashtags
self.assertIn('#indieweb #homebrew website club', preview.content)
self.assertIn('57.7020124, 11.6135007', preview.content)

def test_create_photo_success(self):
Expand Down Expand Up @@ -893,6 +901,12 @@ def test_create_photo_success(self):
json.dumps({'person': {'nsid': '39216764@N00',
'path_alias': 'kindofblue115'}}))

# add regular tags
self.expect_call_api_method('flickr.photos.addTags', {
'photo_id': '9876',
'tags': 'indieweb,"homebrew website club"',
}, '{"stat": "ok"}')

# add person tags
for user_id in ['123@1', '382@123', '456@4']:
self.expect_call_api_method(
Expand Down

0 comments on commit 235faa2

Please sign in to comment.