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: 228
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: 234 lines (+55/-20)
4 files modified
Twitter/ChangeLog (+1/-0)
Twitter/Twitter (+51/-17)
Twitter/Twitter.conf (+1/-1)
Twitter/auto-load.conf (+2/-2)
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+90609@code.launchpad.net

Description of the change

Adding user info, and directives for translations

To post a comment you must log in.
Revision history for this message
Matthieu Baerts (matttbe) wrote :

Thank you ;)

review: Approve

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-01-08 05:09:48 +0000
3+++ Twitter/ChangeLog 2012-01-29 15:25:24 +0000
4@@ -1,2 +1,3 @@
5+0.0.3: (January/14/2012): Possible to see user's info. Translation directives were added on the strings.
6 0.0.2: (January/8/2012): Possible to see the received direct messages.
7 0.0.1: (December/16/2011): Possible to send a tweety, and see the home timeline.
8
9=== modified file 'Twitter/Twitter'
10--- Twitter/Twitter 2012-01-12 01:14:57 +0000
11+++ Twitter/Twitter 2012-01-29 15:25:24 +0000
12@@ -23,11 +23,14 @@
13 # Paste this number on the next dialog box will be shown.
14 # The plugin is going to inform that you are successfully connected.
15
16+# To see the received direct messages right-click on the icon -> Twitter -> Received direct messages
17+# To see some user's info right-click on the icon -> Twitter -> Info
18+
19 import urlparse, os, webbrowser, simplejson
20 from oauth import oauth
21 from http import post, get
22 from util import *
23-from CDApplet import CDApplet
24+from CDApplet import CDApplet, _
25 # TODO import ConfigParser later conver files to config syntax
26 # from threading import Thread
27 # import time
28@@ -76,9 +79,10 @@
29 #class TwitterAPI(threading.Thread):
30 class TwitterAPI():
31 def __init__(self, access_key, access_secret):
32- self.update_url = 'http://twitter.com/statuses/update.json'
33- self.home_timeline_url = 'http://twitter.com/statuses/home_timeline.json'
34- self.direct_messages_url = 'https://api.twitter.com/1/direct_messages.json'
35+ self.update_url = 'http://twitter.com/statuses/update.json'
36+ self.home_timeline_url = 'http://twitter.com/statuses/home_timeline.json'
37+ self.direct_messages_url = 'https://api.twitter.com/1/direct_messages.json'
38+ self.verify_credentials_url = 'https://api.twitter.com/1/account/verify_credentials.json'
39
40 self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
41 consumer_key, consumer_secret = read_consumer_key_and_secret()
42@@ -173,6 +177,16 @@
43 print simplejson.loads(response)[0]
44 return simplejson.loads(response)
45
46+ def verify_credentials(self):
47+ oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
48+ token = self.access_token,
49+ http_url = self.verify_credentials_url,
50+ http_method = "GET")
51+ oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
52+ url = oauth_request.to_url()
53+ response = get(url)
54+ return simplejson.loads(response)
55+
56 class User:
57 def __init__(self, screen_name="", access_key="", access_secret=""):
58 self.screen_name = screen_name
59@@ -195,7 +209,7 @@
60 if len(timeline) > 0:
61 message = "".join (["[<b>%s</b>] %s\n" % (status['user']['name'], status['text']) for status in timeline])
62 else:
63- message = "Oh, dear, your timeline is empty :-("
64+ message = _("Oh, dear, your timeline is empty :-(")
65 dialog = {'use-markup':True}
66 self.inform_end_of_waiting_process()
67 self.show_popup_message(message, dialog)
68@@ -206,7 +220,7 @@
69 if len(messages) > 0:
70 message = "".join (["[<b>%s</b>] %s\n" % (status['sender']['name'], status['text']) for status in messages])
71 else:
72- message = "Oh, dear, you do not have direct messages :-("
73+ message = _("Oh, dear, you do not have direct messages :-(")
74 dialog = {'use-markup':True}
75 self.inform_end_of_waiting_process()
76 self.show_popup_message(message, dialog)
77@@ -216,15 +230,23 @@
78 self.api.update_status(message)
79 self.inform_end_of_waiting_process()
80
81+ # TODO
82+ def show_credentials(self):
83+ self.inform_start_of_waiting_process()
84+ credentials = self.api.verify_credentials()
85+ message = _("%s [<b>%s</b>]\nFollowers: %s\nFriends: %s\nTweets: %s\n") % (credentials['name'], credentials['screen_name'], credentials['followers_count'], credentials['friends_count'], credentials['statuses_count'])
86+ dialog = {'use-markup':True}
87+ self.inform_end_of_waiting_process()
88+ self.show_popup_message(message, dialog)
89+
90 # Applet methods
91
92 def ask_for_tweety(self):
93 dialog = {'buttons':'ok;cancel'}
94 widget = {'widget-type':'text-entry', 'nb-chars':140} # 140 characters max, a tweety :)
95- self.show_popup_message(("%s, send a tweety") % self.user.screen_name, dialog, widget)
96+ self.show_popup_message((_("%s, send a tweety")) % self.user.screen_name, dialog, widget)
97 self.dialog_type = self.responding_tweety
98
99- # TODO: Handle multiple users inside the .users files
100 # TODO: Implement it as a config file using screen_name as section index
101 def read_user_data(self):
102 """Read the users file formated as Screen Name<space>Access Key<space>Access Secret"""
103@@ -232,7 +254,6 @@
104 if os.path.exists(self.user_file):
105 if os.path.getsize(self.user_file) > 0:
106 f = open(self.user_file, "rb")
107- # for line in f:
108 data = f.read()
109 self.user.screen_name, self.user.access_key, self.user.access_secret = data.split() # split the line by space token
110 f.close()
111@@ -245,13 +266,13 @@
112 f.close()
113
114 def show_initial_informations(self):
115- message = "Twitter Applet needs your nickname, and an authorization\nthat you accept it to connect on your Twitter account"
116+ message = _("Twitter Applet needs your nickname, and an authorization\nthat you accept it to connect on your Twitter account")
117 dialog = {'buttons':'next'}
118 self.show_popup_message(message, dialog)
119 self.dialog_type = self.responding_initial_informations
120
121 def ask_for_screen_name(self):
122- message = "What is your Twitter nickname?"
123+ message = _("What is your Twitter nickname?")
124 dialog = {'buttons':'next'}
125 widget = {'widget-type':'text-entry'}
126 self.show_popup_message(message, dialog, widget)
127@@ -263,23 +284,23 @@
128 dialog = {'buttons':'next'}
129 try:
130 webbrowser.open(authorization_url)
131- message = "Twitter applet needs you to give the authorization. Authorization page was opened on your browser. As soon as you authorize it, copy the PIN number that will be shown, and close this dialog"
132+ message = _("Twitter applet needs you to give the authorization. Authorization page was opened on your browser. As soon as you authorize it, copy the PIN number that will be shown, and close this dialog")
133 self.show_popup_message(message, dialog)
134 except webbrowser.Error:
135- message = "Twitter applet needs you to give the authorization. Copy the address bellow and access it with your browser. Copy the PIN number that will be shown as soon as you authorize"
136+ message = _("Twitter applet needs you to give the authorization. Copy the address bellow and access it with your browser. Copy the PIN number that will be shown as soon as you authorize")
137 widget = {'widget-type':'text-entry', 'initial-value':authorization_url}
138 self.show_popup_message(message, dialog, widget)
139 self.dialog_type = self.responding_authorization
140
141 def ask_for_pin_number(self):
142- message = "Enter the PIN number on the authorization page"
143+ message = _("Enter the PIN number on the authorization page")
144 dialog = {'buttons':'next'}
145 widget = {'widget-type':'text-entry'}
146 self.show_popup_message(message, dialog, widget)
147 self.dialog_type = self.responding_pin
148
149 def show_popup_successful_connection(self):
150- self.show_popup_message("Successfully connected with Twitter")
151+ self.show_popup_message(_("Successfully connected with Twitter"))
152
153 def show_popup_message(self, message, dialog={}, widget={}):
154 dialog_attributes = {'message':message}
155@@ -292,13 +313,22 @@
156 direct_messages_menu = []
157 direct_messages_menu.append ({
158 'type' : CDApplet.MENU_ENTRY,
159- 'label' : "Received direct messages",
160- 'menu' : CDApplet.MAIN_MENU_ID,
161+ 'label' : _("Received direct messages"),
162 'id' : self.direct_messages_menu_id,
163 'icon' : os.path.abspath("./data/received.png")
164 })
165 self.icon.AddMenuItems(direct_messages_menu)
166
167+ def build_credentials_menu(self):
168+ credentials_menu = []
169+ credentials_menu.append ({
170+ 'type' : CDApplet.MENU_ENTRY,
171+ 'label' : _("Info"),
172+ 'id' : self.credentials_menu_id,
173+ 'icon' : os.path.abspath("./data/credentials.png")
174+ })
175+ self.icon.AddMenuItems(credentials_menu)
176+
177 def __init__(self):
178 self.user = User()
179 self.user_file = os.path.abspath(os.path.join(os.getcwd(), '..','..','..','.twitter_users')) # ~/.config/.twitter_users
180@@ -309,6 +339,7 @@
181 self.dialog_type = None
182
183 self.direct_messages_menu_id = 1000
184+ self.credentials_menu_id = 2000
185
186 CDApplet.__init__(self) # call CDApplet interface init
187
188@@ -360,10 +391,13 @@
189
190 def on_build_menu(self):
191 self.build_direct_messages_menu()
192+ self.build_credentials_menu()
193
194 def on_menu_select(self, selected_menu):
195 if selected_menu == self.direct_messages_menu_id:
196 self.show_direct_messages()
197+ elif selected_menu == self.credentials_menu_id:
198+ self.show_credentials()
199
200 if __name__ == '__main__':
201 Applet().run()
202
203=== modified file 'Twitter/Twitter.conf'
204--- Twitter/Twitter.conf 2012-01-08 05:09:48 +0000
205+++ Twitter/Twitter.conf 2012-01-29 15:25:24 +0000
206@@ -1,4 +1,4 @@
207-#!en;0.0.2
208+#!en;0.0.3
209
210 #[gtk-about]
211 [Icon]
212
213=== modified file 'Twitter/auto-load.conf'
214--- Twitter/auto-load.conf 2012-01-08 05:09:48 +0000
215+++ Twitter/auto-load.conf 2012-01-29 15:25:24 +0000
216@@ -4,13 +4,13 @@
217 author = Eduardo Mucelli Rezende Oliveira
218
219 # A short description of the applet and how to use it.
220-description = You can send tweets, see your timeline, and the received directed messages.\nOn the first time, the applet is going to ask your nickname and authorization to connect with Twitter.\nThe applet is going to open your browser with the authorization page\nAs soon as you authorize it, a PIN number will be shown on the page, copy this number\nPaste this number on the next dialog box will be shown.\nThe plugin is going to inform that you are successfully connected.
221+description = You can send tweets, see your timeline, and the received directed messages.\nOn the first time, the applet is going to ask your nickname and authorization to connect with Twitter.\nThe applet is going to open your browser with the authorization page\nAs soon as you authorize it, a PIN number will be shown on the page, copy this number\nPaste this number on the next dialog box will be shown.\nThe plugin is going to inform that you are successfully connected.\nTo see the received direct messages right-click on the icon -> Twitter -> Received direct messages.\nTo see some user's info right-click on the icon -> Twitter -> Info.
222
223 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
224 category = 3
225
226 # 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.
227-version = 0.0.2
228+version = 0.0.3
229
230 # Whether the applet can be instanciated several times or not.
231 multi-instance = true
232
233=== added file 'Twitter/data/credentials.png'
234Binary files Twitter/data/credentials.png 1970-01-01 00:00:00 +0000 and Twitter/data/credentials.png 2012-01-29 15:25:24 +0000 differ

Subscribers

People subscribed via source and target branches