cairo-dock-team team mailing list archive
-
cairo-dock-team team
-
Mailing list archive
-
Message #04254
[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras
Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras.
Requested reviews:
Cairo-Dock Team (cairo-dock-team)
For more details, see:
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/107126
Twitter: handling exception when user tries to post the same tweet in a short period of time, twitter returns 403, and identi.ca 401
--
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/107126
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter into lp:cairo-dock-plug-ins-extras.
=== modified file 'Twitter/Twitter'
--- Twitter/Twitter 2012-05-20 12:59:43 +0000
+++ Twitter/Twitter 2012-05-23 22:00:26 +0000
@@ -80,8 +80,7 @@
# Twitter methods
# This method is a callback that is called as soon as a new entry arrives on the stream
- # The method is passed as parameter when creating the instance for the TwitterStreamAPI
- # TwitterStreamAPI(access_key, access_secret, self.on_receive_new_entry_into_stream_callback)
+ # The method is passed as parameter when creating the instance of the twitter API, with get_api method.
def on_receive_new_entry_into_stream_callback(self, entry):
if 'user' in entry: # tweet
if not entry['user']['screen_name'] == self.twitter.user.screen_name: # not sent by the own user
@@ -228,7 +227,8 @@
else:
for network in self.networks:
logp("Sending a tweet with %s '%s'" % (network.name, content))
- network.api.tweet(content)
+ if not network.api.tweet(content):
+ self.show_popup_message(_("Problem to send this tweet on %s, I think you already tried to send the same one few minutes ago" % network.name))
def ask_for_retweet(self, tweet_id):
dialog = {'buttons':'ok;cancel'}
=== modified file 'Twitter/identica.py'
--- Twitter/identica.py 2012-05-20 12:59:43 +0000
+++ Twitter/identica.py 2012-05-23 22:00:26 +0000
@@ -16,6 +16,7 @@
# GNU General Public License for more details.
from oauth import oauth
+from urllib2 import HTTPError
import simplejson
from network import Network
@@ -109,8 +110,16 @@
header = oauth_request.to_header()
post(url, parameters, header)
+ # If an user tries to post the same tweet twice on a short period of time,
+ # twitter is not going to allow, and a error 401 is thrown.
def tweet(self, message): # popularly "send a tweet"
- self.dispatch(self.update_url, "POST", {'status':message})
+ try:
+ self.dispatch(self.update_url, "POST", {'status':message})
+ except HTTPError, err: # urllib2
+ if err.code == 401:
+ return False
+ else:
+ return True
def home_timeline(self):
return self.dispatch(self.home_timeline_url, "GET")
=== modified file 'Twitter/twitter.py'
--- Twitter/twitter.py 2012-05-18 00:00:39 +0000
+++ Twitter/twitter.py 2012-05-23 22:00:26 +0000
@@ -150,18 +150,16 @@
header = oauth_request.to_header()
post(url, parameters, header)
- # TODO: If an user tries to post the same tweet twice on a short period of time,
+ # If an user tries to post the same tweet twice on a short period of time,
# twitter is not going to allow, and a error 403 is thrown.
- # This method should return True based on something like:
- # try:
- # self.dispatch(self.update_url, "POST", {'status':message})
- # except urllib2.HTTPError, err:
- # if err.code == 403:
- # return False
- # else:
- # return True
def tweet(self, message): # popularly "send a tweet"
- self.dispatch(self.update_url, "POST", {'status':message})
+ try:
+ self.dispatch(self.update_url, "POST", {'status':message})
+ except urllib2.HTTPError, err:
+ if err.code == 403:
+ return False
+ else:
+ return True
def retweet(self, tweet_id):
url = "%s%s.json" % (self.retweet_url_prefix, tweet_id)
Follow ups