Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party

Proposed by Eduardo Mucelli Rezende Oliveira
Status: Merged
Merged at revision: 271
Proposed branch: lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter
Merge into: lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
Diff against target: 377 lines (+86/-77)
9 files modified
Twitter/ChangeLog (+1/-0)
Twitter/Twitter (+44/-40)
Twitter/Twitter.conf (+1/-1)
Twitter/auto-load.conf (+1/-1)
Twitter/identica.py (+6/-3)
Twitter/interface.py (+26/-0)
Twitter/menu.py (+1/-1)
Twitter/message.py (+6/-5)
Twitter/networks.py (+0/-26)
To merge this branch: bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter
Reviewer Review Type Date Requested Status
Matthieu Baerts Approve
Review via email: mp+106529@code.launchpad.net

Description of the change

Twitter: Added home timeline for Identi.ca and unification of API calls using self.networks

To post a comment you must log in.
270. By Eduardo Mucelli Rezende Oliveira

I forgot the new images

Revision history for this message
Matthieu Baerts (matttbe) wrote :

No, when I click on 'Tweets' or 'MyTweets' menu entry, this is what I have:

ERROR:dbus.connection:Exception in handler for D-Bus signal:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 230, in maybe_handle_message
    self._handler(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/CDApplet.py", line 177, in _on_menu_select
    self.on_menu_select(iNumEntry)
  File "./Twitter", line 541, in on_menu_select
    self.show_home_timeline() # show the last 20 tweets on the home timeline
  File "./Twitter", line 150, in show_home_timeline
    home_timeline_menu.add(Tweet(text, sender, uid, network.name))
TypeError: __init__() takes exactly 4 arguments (5 given)

Revision history for this message
Matthieu Baerts (matttbe) :
review: Needs Fixing
Revision history for this message
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote :

Yes, I forgot to upload one file. Damn!

On Sun, May 20, 2012 at 3:17 PM, Matthieu Baerts <email address hidden> wrote:

> Review: Needs Fixing
>
>
> --
>
> https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/106529
> You are the owner of
> lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter.
>

--
Eduardo Mucelli R. Oliveira ~
Launchpad<https://launchpad.net/%7Eeduardo-mucelli>

271. By Eduardo Mucelli Rezende Oliveira

Message.py

Revision history for this message
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote :

Good to go. Thanks.

Revision history for this message
Matthieu Baerts (matttbe) wrote :

Thank you ;)

PS: about the commit messages: can you just add the name of the applet at the beginning of your commit messages?
(e.g. "Twitter: added something")
Thanks!

review: Approve
Revision history for this message
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote :

Sometimes I did that, but most of times I forgot, sorry mate.

I am going to do my best to remember. :)

On Sun, May 20, 2012 at 4:29 PM, Matthieu Baerts <email address hidden> wrote:

> Review: Approve
>
> Thank you ;)
>
> PS: about the commit messages: can you just add the name of the applet at
> the beginning of your commit messages?
> (e.g. "Twitter: added something")
> Thanks!
> --
>
> https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/106529
> You are the owner of
> lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter.
>

--
Eduardo Mucelli R. Oliveira ~
Launchpad<https://launchpad.net/%7Eeduardo-mucelli>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Twitter/ChangeLog'
2--- Twitter/ChangeLog 2012-05-18 00:00:39 +0000
3+++ Twitter/ChangeLog 2012-05-20 13:24:19 +0000
4@@ -1,3 +1,4 @@
5+0.4.1 (May/20/2012): Added home timeline on Identi.ca.
6 0.4: (May/18/2012): Fully supporting individually account log-in. Code improvements, refactoring, and bug fixes.
7 0.3: (May/13/2012): Added support to Identi.ca! Many code changes, refactoring, and improving.
8 0.2.2: (April/15/2012): Configurable notifications.
9
10=== modified file 'Twitter/Twitter'
11--- Twitter/Twitter 2012-05-19 00:41:12 +0000
12+++ Twitter/Twitter 2012-05-20 13:24:19 +0000
13@@ -22,12 +22,11 @@
14 # To see the received direct messages right-click on the icon -> Twitter -> [New] direct messages. You can reply any of them by left-clicking on it.
15 # To see some user's info right-click on the icon -> Twitter -> Info
16
17-# TODO:
18-# Add more possibilties to the Identi.ca API
19+# TODO: Add more methods to the Identi.ca API
20
21 import os, webbrowser, Queue
22
23-from networks import Networks # networks.py
24+from interface import Interface # interface.py
25 from twitter import Twitter
26 from identica import Identica
27 import emblem, menu # emblem.py, menu.py
28@@ -36,9 +35,9 @@
29
30 from CDApplet import CDApplet, _
31
32-# Twitter ----> Networks |----> twitter ---> Oauth, TwitterAPI, TwitterStreamAPI
33-# |
34-# |----> identica ---> Oauth, IdenticaAPI
35+# Twitter ----> Interface |----> twitter ---> Oauth, TwitterAPI, TwitterStreamAPI
36+# |
37+# |----> identica ---> Oauth, IdenticaAPI
38
39 class Applet(CDApplet):
40
41@@ -54,7 +53,7 @@
42 self.emblem.update(counter) # create the emblem with the counter
43 self.icon.SetIcon(self.emblem.emblem)
44 else:
45- self.set_visual_for_active_networks()
46+ self.update_visual_for_active_networks()
47
48 def refresh_emblem_size(self):
49 if self.config['emblem_size'] == "Small":
50@@ -109,7 +108,7 @@
51 text = status['text']
52 sender = status['user']['name']
53 uid = status['id_str']
54- ut_menu.add(Tweet(text, sender, uid))
55+ ut_menu.add(Tweet(text, sender, uid, self.twitter.name))
56 ut_menu.pop_up()
57 else:
58 message = _("Oh, dear, your timeline is empty :-(")
59@@ -127,7 +126,7 @@
60 text = tweet['text']
61 sender = tweet['user']['name']
62 uid = tweet['id_str']
63- nt_menu.add(Tweet(text, sender, uid))
64+ nt_menu.add(Tweet(text, sender, uid, self.twitter.name))
65 nt_menu.pop_up()
66
67 self.refresh_emblem_counter()
68@@ -135,20 +134,21 @@
69
70 def show_home_timeline(self):
71 self.inform_start_of_waiting_process()
72+
73+ home_timeline_menu = menu.Menu(self.icon, self.on_tweet_list_menu_clicked)
74
75- timeline = self.twitter.api.home_timeline()
76- if len(timeline) > 0:
77- ht_menu = menu.Menu(self.icon, self.on_tweet_list_menu_clicked)
78- for status in timeline:
79- text = status['text']
80- sender = status['user']['screen_name']
81- uid = status['id_str']
82- ht_menu.add(Tweet(text, sender, uid))
83- ht_menu.pop_up()
84- else:
85- message = _("Oh, dear, your timeline is empty :-(")
86- dialog = {'use-markup':True}
87- self.show_popup_message(message, dialog)
88+ for network in self.networks:
89+ timeline = network.api.home_timeline()
90+ if len(timeline) > 0:
91+ for status in timeline:
92+ text = status['text']
93+ sender = status['user']['screen_name']
94+ if network == self.twitter:
95+ uid = status['id_str']
96+ else:
97+ uid = str(status['statusnet_conversation_id'])
98+ home_timeline_menu.add(Tweet(text, sender, uid, network.name))
99+ home_timeline_menu.pop_up() # pop-uped up twice?
100
101 self.inform_end_of_waiting_process()
102
103@@ -160,7 +160,7 @@
104 direct_message = self.message_stream.get()
105 text = direct_message['direct_message']['text']
106 sender = direct_message['direct_message']['sender']['screen_name']
107- dm_menu.add(DirectMessage(text, sender))
108+ dm_menu.add(DirectMessage(text, sender, self.twitter.name))
109 dm_menu.pop_up()
110
111 self.refresh_emblem_counter()
112@@ -175,7 +175,7 @@
113 for status in messages:
114 text = status['text']
115 sender = status['sender']['screen_name']
116- dm_menu.add(DirectMessage(text, sender))
117+ dm_menu.add(DirectMessage(text, sender, self.twitter.name))
118 dm_menu.pop_up()
119 else:
120 dialog = {'use-markup':True}
121@@ -226,12 +226,9 @@
122 if len(content) > self.tweet_length:
123 self.ask_for_tweet(content, warning=True)
124 else:
125- if self.twitter.api:
126- logp("Sending a tweet with Twitter '%s'" % content)
127- self.twitter.api.tweet(content)
128- if self.identica.api:
129- logp("Sending a tweet with Identi.ca '%s'" % content)
130- self.identica.api.tweet(content)
131+ for network in self.networks:
132+ logp("Sending a tweet with %s '%s'" % (network.name, content))
133+ network.api.tweet(content)
134
135 def ask_for_retweet(self, tweet_id):
136 dialog = {'buttons':'ok;cancel'}
137@@ -309,7 +306,8 @@
138 else:
139 if self.new_network.get_api(): # ... used here, check identica.py method get_api
140 message = _("Successfully connected with Identi.ca")
141- self.set_visual_for_active_networks()
142+ self.update_active_networks()
143+ self.update_visual_for_active_networks()
144 self.show_popup_message(message)
145
146 def show_popup_message(self, message, dialog={}, widget={}):
147@@ -407,10 +405,16 @@
148 }
149 return identica_menu
150
151- def any_active_network(self):
152- return self.twitter.api or self.identica.api
153+ def any_network_is_active(self):
154+ return len(self.networks) > 0
155+
156+ def update_active_networks(self):
157+ if self.twitter.api:
158+ self.networks.append(self.twitter)
159+ if self.identica.api:
160+ self.networks.append(self.identica)
161
162- def set_visual_for_active_networks(self):
163+ def update_visual_for_active_networks(self):
164 if self.twitter.api:
165 self.icon.SetIcon(os.path.abspath("./icon")) # overwrite the alert mark "!!!"
166 if self.identica.api:
167@@ -423,20 +427,19 @@
168
169 def __init__(self):
170
171- # TODO: Rename class, and file
172- self.interface = Networks()
173+ self.interface = Interface()
174
175 self.twitter = self.interface.twitter()
176 self.identica = self.interface.identica()
177
178- # self.networks = [] # self.twitter, self.identica
179+ self.networks = [] # active networks
180
181 (self.responding_screen_name, self.responding_authorization, self.responding_pin,
182 self.responding_success, self.responding_tweet, self.responding_initial_informations,
183 self.responding_sending_direct_message_reply, self.responding_retweet) = range(8)
184 self.dialog_type = None
185
186- self.emblem = emblem.Emblem() # emblem maker, see emblem.py
187+ self.emblem = emblem.Emblem() # emblem maker, see emblem.py
188
189 self.direct_messages_menu_id = 1000
190 self.credentials_menu_id = 2000
191@@ -462,7 +465,8 @@
192 elif not self.identica.get_api():
193 logm("User not found")
194 self.show_inexistence_of_networks()
195- self.set_visual_for_active_networks()
196+ self.update_active_networks()
197+ self.update_visual_for_active_networks()
198
199 def get_config(self, keyfile):
200 self.config['emblem_size'] = keyfile.get('Configuration', 'emblem_size')
201@@ -502,7 +506,7 @@
202 elif not self.message_stream.empty():
203 self.show_new_direct_messages()
204 else:
205- if self.any_active_network():
206+ if self.any_network_is_active():
207 self.ask_for_tweet()
208
209 def on_middle_click(self):
210
211=== modified file 'Twitter/Twitter.conf'
212--- Twitter/Twitter.conf 2012-05-18 00:00:39 +0000
213+++ Twitter/Twitter.conf 2012-05-20 13:24:19 +0000
214@@ -1,4 +1,4 @@
215-#0.4
216+#0.4.1
217
218 #[gtk-about]
219 [Icon]
220
221=== modified file 'Twitter/auto-load.conf'
222--- Twitter/auto-load.conf 2012-05-18 00:00:39 +0000
223+++ Twitter/auto-load.conf 2012-05-20 13:24:19 +0000
224@@ -10,7 +10,7 @@
225 category = 3
226
227 # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file.
228-version = 0.4
229+version = 0.4.1
230
231 # Whether the applet can be instanciated several times or not.
232 multi-instance = true
233
234=== added file 'Twitter/data/message_identica.png'
235Binary files Twitter/data/message_identica.png 1970-01-01 00:00:00 +0000 and Twitter/data/message_identica.png 2012-05-20 13:24:19 +0000 differ
236=== removed file 'Twitter/data/message_small.png'
237Binary files Twitter/data/message_small.png 2012-03-22 00:14:49 +0000 and Twitter/data/message_small.png 1970-01-01 00:00:00 +0000 differ
238=== added file 'Twitter/data/message_twitter.png'
239Binary files Twitter/data/message_twitter.png 1970-01-01 00:00:00 +0000 and Twitter/data/message_twitter.png 2012-05-20 13:24:19 +0000 differ
240=== modified file 'Twitter/identica.py'
241--- Twitter/identica.py 2012-05-18 00:00:39 +0000
242+++ Twitter/identica.py 2012-05-20 13:24:19 +0000
243@@ -16,7 +16,7 @@
244 # GNU General Public License for more details.
245
246 from oauth import oauth
247-import urllib2, urllib
248+import simplejson
249
250 from network import Network
251 from user import User
252@@ -91,7 +91,8 @@
253 self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
254 self.access_token = oauth.OAuthToken(access_key, access_secret)
255
256- self.update_url = 'http://identi.ca/api/statuses/update.json'
257+ self.update_url = 'http://identi.ca/api/statuses/update.json'
258+ self.home_timeline_url = 'http://identi.ca/api/statuses/home_timeline.json'
259
260 def dispatch(self, url, mode, parameters={}):
261 oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
262@@ -100,7 +101,6 @@
263 parameters = parameters,
264 http_method = mode)
265 oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
266-# logp(oauth_request.to_url())
267 if mode == "GET":
268 url = oauth_request.to_url()
269 response = get(url)
270@@ -111,3 +111,6 @@
271
272 def tweet(self, message): # popularly "send a tweet"
273 self.dispatch(self.update_url, "POST", {'status':message})
274+
275+ def home_timeline(self):
276+ return self.dispatch(self.home_timeline_url, "GET")
277
278=== added file 'Twitter/interface.py'
279--- Twitter/interface.py 1970-01-01 00:00:00 +0000
280+++ Twitter/interface.py 2012-05-20 13:24:19 +0000
281@@ -0,0 +1,26 @@
282+#!/usr/bin/python
283+
284+# This is a part of the external Twitter applet for Cairo-Dock
285+#
286+# Author: Eduardo Mucelli Rezende Oliveira
287+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
288+#
289+# This program is free software: you can redistribute it and/or modify
290+# it under the terms of the GNU General Public License as published by
291+# the Free Software Foundation, either version 3 of the License, or
292+# (at your option) any later version.
293+
294+# This program is distributed in the hope that it will be useful,
295+# but WITHOUT ANY WARRANTY; without even the implied warranty of
296+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297+# GNU General Public License for more details.
298+
299+class Interface:
300+
301+ def twitter(self):
302+ from twitter import Twitter
303+ return Twitter()
304+
305+ def identica(self):
306+ from identica import Identica
307+ return Identica()
308
309=== modified file 'Twitter/menu.py'
310--- Twitter/menu.py 2012-03-22 00:14:49 +0000
311+++ Twitter/menu.py 2012-05-20 13:24:19 +0000
312@@ -28,7 +28,7 @@
313 item.set_label(message.sender) # used to track who sent the message in order to reply it.
314 elif isinstance(message, Tweet):
315 item.set_label(message.uid) # used to retweet the tweet
316- item.set_image(gtk.image_new_from_file(os.path.abspath("./data/message_small.png")))
317+ item.set_image(gtk.image_new_from_file(os.path.abspath("./data/message_%s.png" % message.network)))
318 text = "<b>%s</b>\n%s" % (message.sender, message.text)
319 item.get_children()[0].set_markup(text)
320 if self.callback: # for tweets posted by the user, there is not callback to be set
321
322=== modified file 'Twitter/message.py'
323--- Twitter/message.py 2012-05-13 00:58:06 +0000
324+++ Twitter/message.py 2012-05-20 13:24:19 +0000
325@@ -17,15 +17,16 @@
326
327 # Can be either a Tweet or a Direct Message
328 class Message:
329- def __init__(self, text, sender):
330+ def __init__(self, text, sender, network):
331 self.text = text
332 self.sender = sender
333+ self.network = network
334
335 class DirectMessage(Message):
336- def __init__(self, text, sender):
337- Message.__init__(self, text, sender)
338+ def __init__(self, text, sender, network):
339+ Message.__init__(self, text, sender, network)
340
341 class Tweet(Message):
342- def __init__(self, text, sender, uid):
343- Message.__init__(self, text, sender)
344+ def __init__(self, text, sender, uid, network):
345+ Message.__init__(self, text, sender, network)
346 self.uid = uid # it is going to be used to retweet this Tweet
347
348=== removed file 'Twitter/networks.py'
349--- Twitter/networks.py 2012-05-13 00:58:06 +0000
350+++ Twitter/networks.py 1970-01-01 00:00:00 +0000
351@@ -1,26 +0,0 @@
352-#!/usr/bin/python
353-
354-# This is a part of the external Twitter applet for Cairo-Dock
355-#
356-# Author: Eduardo Mucelli Rezende Oliveira
357-# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
358-#
359-# This program is free software: you can redistribute it and/or modify
360-# it under the terms of the GNU General Public License as published by
361-# the Free Software Foundation, either version 3 of the License, or
362-# (at your option) any later version.
363-
364-# This program is distributed in the hope that it will be useful,
365-# but WITHOUT ANY WARRANTY; without even the implied warranty of
366-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
367-# GNU General Public License for more details.
368-
369-class Networks:
370-
371- def twitter(self):
372- from twitter import Twitter
373- return Twitter()
374-
375- def identica(self):
376- from identica import Identica
377- return Identica()

Subscribers

People subscribed via source and target branches