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: 225
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: 173 lines (+71/-16)
1 file modified
Twitter/Twitter (+71/-16)
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+87857@code.launchpad.net

Description of the change

Starting and authorization steps as wizard. Ps.: There are many commented parts that belongs to improvements for the next versions ... but not yet finished :)

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

Thank you for this new version!

PS: don't forget to move the '.users' file to ~/.config/cairo-dock directory just like does Gmail applet. (to not include it on our website (if this file is saved into the directory of the applet) or on a theme (if it is saved in the same directory than the .conf file of the applet: ~/.config/cairo-dock/current_theme/plug-ins/(...) )). E.g.:

=== modified file 'Twitter/Twitter'
--- Twitter/Twitter 2012-01-07 20:55:28 +0000
+++ Twitter/Twitter 2012-01-07 18:44:27 +0000
@@ -268,7 +268,8 @@

   def __init__(self):
     self.user = User()
- self.user_file = '.users'
+ self.path = sys.argv[3][0:-10] # relative path to config file's folder
+ self.user_file = self.path+'../../../.Twitter_users'
     self.twitter_auth = TwitterOauth()
     self.api = None
     self.responding_screen_name, self.responding_authorization, self.responding_pin, self.responding_success, self.responding_tweety, self.responding_initial_informations = range(6)

Revision history for this message
Matthieu Baerts (matttbe) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Twitter/Twitter'
2--- Twitter/Twitter 2011-12-18 02:15:50 +0000
3+++ Twitter/Twitter 2012-01-07 18:16:24 +0000
4@@ -29,6 +29,8 @@
5 from util import *
6 from CDApplet import CDApplet
7 # TODO import ConfigParser later conver files to config syntax
8+# from threading import Thread
9+# import time
10
11 class TwitterOauth:
12 def __init__(self):
13@@ -71,17 +73,32 @@
14 access_token_data = dict((x, y) for x, y in urlparse.parse_qsl(response)) # tuple to dict
15 return access_token_data['oauth_token'], access_token_data['oauth_token_secret']
16
17-class TwitterAPI:
18+#class TwitterAPI(threading.Thread):
19+class TwitterAPI():
20 def __init__(self, access_key, access_secret):
21 self.update_url = 'http://twitter.com/statuses/update.json'
22 self.home_timeline_url = 'http://twitter.com/statuses/home_timeline.json'
23- self.tweety_streaming_url = 'https://userstream.twitter.com/2/user.json'
24
25 self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
26 consumer_key, consumer_secret = read_consumer_key_and_secret()
27 self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
28 self.access_token = oauth.OAuthToken(access_key, access_secret)
29
30+# self.current_home_timeline = self.home_timeline()
31+# self.current_last_status_time = time.strptime(self.current_home_timeline[0]['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
32+# print "==== initial last time ========="
33+# print self.current_home_timeline[0]['text']
34+# print self.current_last_status_time
35+# print "============="
36+# t = Thread(target=self.check_home_timeline())
37+# t.start()
38+# t.join()
39+# self.check_home_timeline()
40+ #threading.Thread.__init__(self)
41+
42+# def run(self):
43+# self.check_home_timeline()
44+
45 # def tweety_streaming(self):
46 # oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
47 # token = self.access_token,
48@@ -103,6 +120,37 @@
49 post_data = oauth_request.to_postdata()
50 return post(self.update_url, post_data)
51
52+# def check_home_timeline(self):
53+# i = 0
54+# while i < 5:
55+# new_home_timeline = self.home_timeline()
56+# new_tweetys = []
57+# if self.current_home_timeline:
58+# for status in new_home_timeline:
59+# #if status['created_at'] > self.current_last_status_time:
60+# if time.strptime(status['created_at'], "%a %b %d %H:%M:%S +0000 %Y") > self.current_last_status_time:
61+# print "==== found greater last time ========="
62+# print status['text']
63+# print status['created_at']
64+# print "============="
65+# new_tweetys.append(status)
66+# logp("Thread - Changed home timeline")
67+# self.current_home_timeline = new_home_timeline
68+# message = "".join (["[%s] %s\n" % (status['user']['name'], status['text']) for status in new_tweetys])
69+# logp(message)
70+# #self.show_popup_message(message)
71+# self.current_last_status_time = time.strptime(self.current_home_timeline[0]['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
72+# print "==== novo greater last time ========="
73+# print status['text']
74+# print status['created_at']
75+# print "============="
76+# #self.current_last_status_time = self.current_home_timeline[0]['created_at']
77+# else:
78+# logp("Thread - Fetching home timeline")
79+# self.current_home_timeline = new_home_timeline
80+# time.sleep(20)
81+# i+=1
82+
83 def home_timeline(self):
84 oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
85 token = self.access_token,
86@@ -110,7 +158,7 @@
87 http_method = "GET")
88 oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
89 url = oauth_request.to_url()
90- response = get(url)
91+ response = get(url)
92 return simplejson.loads(response)
93
94 class User:
95@@ -174,31 +222,36 @@
96 f.write("%s %s %s" % (self.user.screen_name, self.user.access_key, self.user.access_secret))
97 f.close()
98
99+ def show_initial_informations(self):
100+ message = "Twitter Applet needs your nickname, and an authorization\nthat you accept it to connect on your Twitter account"
101+ dialog = {'buttons':'next'}
102+ self.show_popup_message(message, dialog)
103+ self.dialog_type = self.responding_initial_informations
104+
105 def ask_for_screen_name(self):
106 message = "What is your Twitter nickname?"
107- dialog = {'buttons':'ok'}
108+ dialog = {'buttons':'next'}
109 widget = {'widget-type':'text-entry'}
110 self.show_popup_message(message, dialog, widget)
111- # self.dialog_type = self.responding_screen_name
112+ self.dialog_type = self.responding_screen_name
113
114 def ask_for_authorization(self):
115 authorization_url = self.twitter_auth.get_authorization_url()
116 logp("Opening the auth URL '%s'" % authorization_url)
117+ dialog = {'buttons':'next'}
118 try:
119 webbrowser.open(authorization_url)
120- message = "Twitter applet needs you to give the authorization. Authorization page was opened on your browser. As soon as you do, copy the PIN number that will be shown, and close this dialog"
121- dialog = {'buttons':'ok'}
122+ 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"
123 self.show_popup_message(message, dialog)
124 except webbrowser.Error:
125 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"
126- dialog = {'buttons':'ok'}
127 widget = {'widget-type':'text-entry', 'initial-value':authorization_url}
128 self.show_popup_message(message, dialog, widget)
129 self.dialog_type = self.responding_authorization
130
131 def ask_for_pin_number(self):
132 message = "Enter the PIN number on the authorization page"
133- dialog = {'buttons':'ok'}
134+ dialog = {'buttons':'next'}
135 widget = {'widget-type':'text-entry'}
136 self.show_popup_message(message, dialog, widget)
137 self.dialog_type = self.responding_pin
138@@ -218,18 +271,18 @@
139 self.user_file = '.users'
140 self.twitter_auth = TwitterOauth()
141 self.api = None
142- self.responding_screen_name, self.responding_authorization, self.responding_pin, self.responding_success, self.responding_tweety = range(5)
143- self.dialog_type = self.responding_screen_name
144+ self.responding_screen_name, self.responding_authorization, self.responding_pin, self.responding_success, self.responding_tweety, self.responding_initial_informations = range(6)
145+ self.dialog_type = None
146
147- CDApplet.__init__(self) # call CDApplet interface init
148+ CDApplet.__init__(self) # call CDApplet interface init
149
150 # Inherited methods from CDApplet
151 def begin(self):
152 logp("Looking for user ...")
153- if not self.read_user_data(): # first time for the user
154+ if not self.read_user_data(): # first time for the user
155 logm("User not found")
156- self.ask_for_screen_name() # start asking for its screen name
157- else: # user not found
158+ self.show_initial_informations() # start the wizard
159+ else: # user not found
160 logp("User '%s' found" % self.user.screen_name)
161 self.api = TwitterAPI(self.user.access_key, self.user.access_secret) # getting control over the api
162
163@@ -240,7 +293,9 @@
164 # Callbacks
165 def on_answer_dialog(self, key, content):
166 if (key == 0 or key == -1): # ... and pressed Ok or Enter
167- if self.dialog_type == self.responding_screen_name: # user typed screen name ...
168+ if self.dialog_type == self.responding_initial_informations:
169+ self.ask_for_screen_name()
170+ elif self.dialog_type == self.responding_screen_name: # user typed screen name ...
171 logp("Receiving screen name '%s'" % content)
172 self.user.screen_name = content
173 self.ask_for_authorization()

Subscribers

People subscribed via source and target branches