Merge lp:~kai-mast/friends/facebook-link-picture-size into lp:friends

Proposed by Kai Mast
Status: Merged
Merged at revision: 250
Proposed branch: lp:~kai-mast/friends/facebook-link-picture-size
Merge into: lp:friends
Diff against target: 95 lines (+28/-7)
4 files modified
friends/protocols/facebook.py (+22/-3)
friends/protocols/twitter.py (+3/-0)
friends/tests/test_facebook.py (+2/-3)
friends/tests/test_twitter.py (+1/-1)
To merge this branch: bzr merge lp:~kai-mast/friends/facebook-link-picture-size
Reviewer Review Type Date Requested Status
Robert Bruce Park Needs Fixing
Review via email: mp+203629@code.launchpad.net

Description of the change

Looks good to me now.

I also added the image stream stuff to Twitter too. Would really be nicer if messages could be in one than more stream though.

To post a comment you must log in.
Revision history for this message
Kai Mast (kai-mast) wrote :

Oh, I also filtered the wall posts out of the stream. They don't really make sense when displayed as normal posts.

Revision history for this message
Robert Bruce Park (robru) wrote :

Looks mostly good, but here's some improvements you can make:

    if (message_id is None) or (message_type is None):

should be:

    if None in (message_id, message_type):

and then:

    if to and not (to is ""):

Not sure what you're even trying to do here. if "to" is an empty string, it will evaluate false in python. So this is already equivalent:

    if to:

then:

    place = entry.get('place') or {}
    location = place.get('location') or {}

should be:

    place = entry.get('place', {})
    location = place.get('location', {})

and:

    if not (picture_url is ''):

can be:

    if picture_url:

review: Needs Fixing
234. By Kai Mast

Cleanups

Revision history for this message
Kai Mast (kai-mast) wrote :

Thanks for the hints. Still getting used to python. Should be cleaned up now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'friends/protocols/facebook.py'
2--- friends/protocols/facebook.py 2013-11-05 20:22:00 +0000
3+++ friends/protocols/facebook.py 2014-01-28 22:04:43 +0000
4@@ -60,19 +60,38 @@
5
6 def _publish_entry(self, entry, stream='messages'):
7 message_id = entry.get('id')
8- if message_id is None:
9+ to = entry.get('to')
10+ message_type = entry.get('type')
11+
12+ if "reply" in stream:
13+ message_type = "reply"
14+
15+ if None in (message_id, message_type):
16 # We can't do much with this entry.
17 return
18+
19+ if to:
20+ # Somebody posted on somebodies wall
21+ # This cannot be displayed properly in friends so ignore
22+ return
23
24 place = entry.get('place', {})
25 location = place.get('location', {})
26
27+ link_pic = entry.get('picture', '')
28+
29+ # Use objectID to get a highres version of the picture
30+ # Does not seem to work for links
31+ object_id = entry.get('object_id')
32+ if object_id and ('photo' in message_type):
33+ link_pic = "http://graph.facebook.com/" + object_id + "/picture?type=normal"
34+
35 args = dict(
36 message_id=message_id,
37- stream=stream,
38+ stream='images' if ('photo' in message_type) else stream,
39 message=entry.get('message', '') or entry.get('story', ''),
40 icon_uri=entry.get('icon', ''),
41- link_picture=entry.get('picture', ''),
42+ link_picture=link_pic,
43 link_name=entry.get('name', ''),
44 link_url=entry.get('link', ''),
45 link_desc=entry.get('description', ''),
46
47=== modified file 'friends/protocols/twitter.py'
48--- friends/protocols/twitter.py 2014-01-24 18:11:23 +0000
49+++ friends/protocols/twitter.py 2014-01-28 22:04:43 +0000
50@@ -175,6 +175,9 @@
51 message
52 )
53
54+ if picture_url:
55+ stream = 'images'
56+
57 self._publish(
58 message_id=tweet_id,
59 message=message,
60
61=== modified file 'friends/tests/test_facebook.py'
62--- friends/tests/test_facebook.py 2013-07-29 22:10:41 +0000
63+++ friends/tests/test_facebook.py 2014-01-28 22:04:43 +0000
64@@ -173,7 +173,7 @@
65 'facebook',
66 88,
67 '161247843901324_629147610444676',
68- 'mentions',
69+ 'images',
70 'Best Western Denver Southwest',
71 '161247843901324',
72 'Best Western Denver Southwest',
73@@ -189,8 +189,7 @@
74 'https://www.facebook.com/161247843901324/posts/629147610444676',
75 84,
76 False,
77- 'https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc7/' +
78- '601266_629147587111345_968504279_s.jpg',
79+ 'http://graph.facebook.com/629147587111345/picture?type=normal',
80 '',
81 'https://www.facebook.com/photo.php?fbid=629147587111345&set=a.173256162700492.47377.161247843901324&type=1&relevant_count=1',
82 '',
83
84=== modified file 'friends/tests/test_twitter.py'
85--- friends/tests/test_twitter.py 2014-01-24 18:11:23 +0000
86+++ friends/tests/test_twitter.py 2014-01-28 22:04:43 +0000
87@@ -142,7 +142,7 @@
88 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
89 ],
90 ['twitter', 88, '240556426106372096',
91- 'messages', 'Raffi Krikorian', '8285392', 'raffi', False,
92+ 'images', 'Raffi Krikorian', '8285392', 'raffi', False,
93 '2012-08-28T21:08:15Z', 'lecturing at the "analyzing big data '
94 'with twitter" class at <a href="https://twitter.com/Cal">@Cal</a>'
95 ' with <a href="https://twitter.com/othman">@othman</a> '

Subscribers

People subscribed via source and target branches

to all changes: