Merge lp:~stefanor/ibid/twitter-rt-554906 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 945
Merged at revision: 956
Proposed branch: lp:~stefanor/ibid/twitter-rt-554906
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 67 lines (+30/-14)
1 file modified
ibid/plugins/social.py (+30/-14)
To merge this branch: bzr merge lp:~stefanor/ibid/twitter-rt-554906
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Max Rabkin Approve
Jonathan Hitchcock Approve
Review via email: mp+26831@code.launchpad.net

Commit message

Display latest tweets from retweeting-twits instead of thinking they don't exist

Description of the change

Pretty straightforward fix. They don't kneecap the Atom feed

Proposed for 0.1

To post a comment you must log in.
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Max Rabkin (max-rabkin) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/social.py'
2--- ibid/plugins/social.py 2010-03-27 15:50:58 +0000
3+++ ibid/plugins/social.py 2010-06-04 19:13:23 +0000
4@@ -9,10 +9,11 @@
5
6 import feedparser
7
8-from ibid.compat import dt_strptime
9+from ibid.compat import dt_strptime, ElementTree
10 from ibid.config import DictOption
11 from ibid.plugins import Processor, match, handler
12-from ibid.utils import ago, decode_htmlentities, json_webservice
13+from ibid.utils import ago, decode_htmlentities, generic_webservice, \
14+ json_webservice
15
16 log = logging.getLogger('plugins.social')
17 features = {}
18@@ -71,23 +72,38 @@
19 return {'screen_name': status['user']['screen_name'], 'text': decode_htmlentities(status['text'])}
20
21 def remote_latest(self, service, user):
22- statuses = json_webservice(
23- '%sstatuses/user_timeline/%s.json' % (service['endpoint'], user.encode('utf-8')),
24- {'count': 1})
25-
26- if not statuses:
27- raise self.NoSuchUserException(user)
28-
29- latest = statuses[0]
30-
31 if service['api'] == 'twitter':
32- url = '%s%s/status/%i' % (service['endpoint'], latest['user']['screen_name'], latest['id'])
33+ # Twitter ommits retweets in the JSON and XML results:
34+ statuses = generic_webservice('%sstatuses/user_timeline/%s.atom'
35+ % (service['endpoint'], user.encode('utf-8')),
36+ {'count': 1})
37+ tree = ElementTree.fromstring(statuses)
38+ latest = tree.find('{http://www.w3.org/2005/Atom}entry')
39+ return {
40+ 'text': latest.findtext('{http://www.w3.org/2005/Atom}content')
41+ .split(': ', 1)[1],
42+ 'ago': ago(datetime.utcnow() - dt_strptime(
43+ latest.findtext('{http://www.w3.org/2005/Atom}published'),
44+ '%Y-%m-%dT%H:%M:%S+00:00')),
45+ 'url': [x for x
46+ in latest.getiterator('{http://www.w3.org/2005/Atom}link')
47+ if x.get('type') == 'text/html'
48+ ][0].get('href'),
49+ }
50 elif service['api'] == 'laconica':
51- url = '%s/notice/%i' % (service['endpoint'].split('/api/', 1)[0], latest['id'])
52+ statuses = json_webservice('%sstatuses/user_timeline/%s.json'
53+ % (service['endpoint'], user.encode('utf-8')),
54+ {'count': 1})
55+ if not statuses:
56+ raise self.NoSuchUserException(user)
57+ latest = statuses[0]
58+ url = '%s/notice/%i' % (service['endpoint'].split('/api/', 1)[0],
59+ latest['id'])
60
61 return {
62 'text': decode_htmlentities(latest['text']),
63- 'ago': ago(datetime.utcnow() - dt_strptime(latest['created_at'], '%a %b %d %H:%M:%S +0000 %Y')),
64+ 'ago': ago(datetime.utcnow() - dt_strptime(latest['created_at'],
65+ '%a %b %d %H:%M:%S +0000 %Y')),
66 'url': url,
67 }
68

Subscribers

People subscribed via source and target branches