~kobe24-lixiang/friends/friends

« back to all changes in this revision

Viewing changes to friends/protocols/flickr.py

  • Committer: Tarmac
  • Author(s): Robert Bruce Park
  • Date: 2013-03-26 18:10:46 UTC
  • mfrom: (169.1.1 fix-flickr-images)
  • Revision ID: tarmac-20130326181046-rmxqnsy4te1ufmbh
Correctly generate flickr photo URLs. (LP: #1159979). Fixes: https://bugs.launchpad.net/bugs/1159979.

Approved by PS Jenkins bot, Ken VanDine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
# http://www.flickr.com/services/api/misc.buddyicons.html
45
45
FARM = 'http://farm{farm}.static.flickr.com/{server}/'
46
46
BUDDY_ICON_URL = FARM + 'buddyicons/{nsid}.jpg'
47
 
IMAGE_URL = FARM + '{nsid}_{secret}_{type}.jpg'
48
 
IMAGE_PAGE_URL = 'http://www.flickr.com/photos/{owner}/{nsid}'
 
47
IMAGE_URL = FARM + '{photo}_{secret}_{type}.jpg'
 
48
IMAGE_PAGE_URL = 'http://www.flickr.com/photos/{owner}/{photo}'
49
49
PEOPLE_URL = 'http://www.flickr.com/people/{owner}'
50
50
 
51
51
 
121
121
            # Pre-calculate some values to publish.
122
122
            username = data.get('username', '')
123
123
            ownername = data.get('ownername', '')
 
124
            photo_id = data.get('id')
 
125
 
 
126
            if photo_id is None:
 
127
                # Can't do anything without this, really.
 
128
                continue
124
129
 
125
130
            # Icons.
126
131
            icon_farm = data.get('iconfarm')
132
137
            if None not in (icon_farm, icon_server, owner):
133
138
                icon_uri = Avatar.get_image(BUDDY_ICON_URL.format(
134
139
                    farm=icon_farm, server=icon_server, nsid=owner))
135
 
                url = PEOPLE_URL.format(owner=owner)
 
140
                url = IMAGE_PAGE_URL.format(owner=owner, photo=photo_id)
136
141
 
137
142
            # Calculate the ISO 8601 UTC time string.
138
143
            try:
144
149
            farm = data.get('farm')
145
150
            server = data.get('server')
146
151
            secret = data.get('secret')
147
 
            img_url = ''
148
 
            img_src = ''
149
 
            img_thumb = ''
 
152
            img_src, img_thumb = '', ''
150
153
            if None not in (farm, server, secret):
151
 
                args = dict(farm=farm, server=server, nsid=owner, secret=secret)
152
 
                img_url = IMAGE_URL.format(type='b', **args)
 
154
                args = dict(
 
155
                    farm=farm,
 
156
                    server=server,
 
157
                    photo=photo_id,
 
158
                    secret=secret,
 
159
                    )
153
160
                img_src = IMAGE_URL.format(type='m', **args)
154
161
                img_thumb = IMAGE_URL.format(type='t', **args)
155
162
 
156
163
            self._publish(
157
 
                message_id=data.get('id', ''),
 
164
                message_id=photo_id,
 
165
                message=data.get('title', ''),
158
166
                stream='images',
159
167
                sender=ownername,
160
168
                sender_id=owner,
163
171
                url=url,
164
172
                from_me=from_me,
165
173
                timestamp=timestamp,
166
 
                link_caption=data.get('title', ''),
167
 
                link_url=img_url,
 
174
                link_url=url,
168
175
                link_picture=img_src,
169
176
                link_icon=img_thumb,
170
177
                latitude=data.get('latitude', 0.0),
204
211
        else:
205
212
            destination_url = IMAGE_PAGE_URL.format(
206
213
                owner=self._account.user_name,
207
 
                nsid=post_id,
 
214
                photo=post_id,
208
215
                )
209
216
            self._publish(
210
217
                from_me=True,