← Back to team overview

cairo-dock-team team mailing list archive

[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/106529

Twitter: Added home timeline for Identi.ca and unification of API calls using self.networks
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/106529
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/ChangeLog'
--- Twitter/ChangeLog	2012-05-18 00:00:39 +0000
+++ Twitter/ChangeLog	2012-05-20 13:03:18 +0000
@@ -1,3 +1,4 @@
+0.4.1 (May/20/2012): Added home timeline on Identi.ca.
 0.4: (May/18/2012): Fully supporting individually account log-in. Code improvements, refactoring, and bug fixes.
 0.3: (May/13/2012): Added support to Identi.ca! Many code changes, refactoring, and improving.
 0.2.2: (April/15/2012): Configurable notifications.

=== modified file 'Twitter/Twitter'
--- Twitter/Twitter	2012-05-19 00:41:12 +0000
+++ Twitter/Twitter	2012-05-20 13:03:18 +0000
@@ -22,12 +22,11 @@
 # 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.
 # To see some user's info right-click on the icon -> Twitter -> Info
 
-# TODO:
-#       Add more possibilties to the Identi.ca API
+# TODO: Add more methods to the Identi.ca API
 
 import os, webbrowser, Queue
 
-from networks import Networks                                                   # networks.py
+from interface import Interface                                                 # interface.py
 from twitter import Twitter
 from identica import Identica
 import emblem, menu                                                             # emblem.py, menu.py
@@ -36,9 +35,9 @@
 
 from CDApplet import CDApplet, _
 
-# Twitter ----> Networks |----> twitter  ---> Oauth, TwitterAPI, TwitterStreamAPI
-#                        |
-#                        |----> identica ---> Oauth, IdenticaAPI
+# Twitter ----> Interface |----> twitter  ---> Oauth, TwitterAPI, TwitterStreamAPI
+#                         |
+#                         |----> identica ---> Oauth, IdenticaAPI
 
 class Applet(CDApplet):
 
@@ -54,7 +53,7 @@
       self.emblem.update(counter)                                                               # create the emblem with the counter
       self.icon.SetIcon(self.emblem.emblem)
     else:
-      self.set_visual_for_active_networks()
+      self.update_visual_for_active_networks()
     
   def refresh_emblem_size(self):
     if self.config['emblem_size'] == "Small":
@@ -109,7 +108,7 @@
         text = status['text']
         sender = status['user']['name']
         uid = status['id_str']
-        ut_menu.add(Tweet(text, sender, uid))
+        ut_menu.add(Tweet(text, sender, uid, self.twitter.name))
       ut_menu.pop_up()
     else:
       message = _("Oh, dear, your timeline is empty :-(")
@@ -127,7 +126,7 @@
       text = tweet['text']
       sender = tweet['user']['name']
       uid = tweet['id_str']
-      nt_menu.add(Tweet(text, sender, uid))
+      nt_menu.add(Tweet(text, sender, uid, self.twitter.name))
     nt_menu.pop_up()
     
     self.refresh_emblem_counter() 
@@ -135,20 +134,21 @@
 
   def show_home_timeline(self):
     self.inform_start_of_waiting_process()
+   
+    home_timeline_menu = menu.Menu(self.icon, self.on_tweet_list_menu_clicked)
     
-    timeline = self.twitter.api.home_timeline()
-    if len(timeline) > 0:
-      ht_menu = menu.Menu(self.icon, self.on_tweet_list_menu_clicked)
-      for status in timeline:
-        text = status['text']
-        sender = status['user']['screen_name']
-        uid = status['id_str']
-        ht_menu.add(Tweet(text, sender, uid))
-      ht_menu.pop_up()
-    else:
-      message = _("Oh, dear, your timeline is empty :-(")
-      dialog = {'use-markup':True}
-      self.show_popup_message(message, dialog)
+    for network in self.networks:
+      timeline = network.api.home_timeline()
+      if len(timeline) > 0:
+        for status in timeline:
+          text = status['text']
+          sender = status['user']['screen_name']
+          if network == self.twitter:
+            uid = status['id_str']
+          else:
+            uid = str(status['statusnet_conversation_id'])
+          home_timeline_menu.add(Tweet(text, sender, uid, network.name))
+        home_timeline_menu.pop_up()                                                         # pop-uped up twice?
       
     self.inform_end_of_waiting_process()
 
@@ -160,7 +160,7 @@
       direct_message = self.message_stream.get()
       text = direct_message['direct_message']['text']
       sender = direct_message['direct_message']['sender']['screen_name']
-      dm_menu.add(DirectMessage(text, sender))
+      dm_menu.add(DirectMessage(text, sender, self.twitter.name))
     dm_menu.pop_up()
 
     self.refresh_emblem_counter()
@@ -175,7 +175,7 @@
       for status in messages:
         text = status['text']
         sender = status['sender']['screen_name']
-        dm_menu.add(DirectMessage(text, sender))
+        dm_menu.add(DirectMessage(text, sender, self.twitter.name))
       dm_menu.pop_up()
     else:
       dialog = {'use-markup':True}
@@ -226,12 +226,9 @@
     if len(content) > self.tweet_length:
       self.ask_for_tweet(content, warning=True)
     else:
-      if self.twitter.api:
-        logp("Sending a tweet with Twitter '%s'" % content)
-        self.twitter.api.tweet(content)
-      if self.identica.api:
-        logp("Sending a tweet with Identi.ca '%s'" % content)
-        self.identica.api.tweet(content)
+      for network in self.networks:
+        logp("Sending a tweet with %s '%s'" % (network.name, content))
+        network.api.tweet(content)
     
   def ask_for_retweet(self, tweet_id):
     dialog = {'buttons':'ok;cancel'}
@@ -309,7 +306,8 @@
     else:
       if self.new_network.get_api():                                                            # ... used here, check identica.py method get_api
         message = _("Successfully connected with Identi.ca")
-    self.set_visual_for_active_networks()
+    self.update_active_networks()
+    self.update_visual_for_active_networks()
     self.show_popup_message(message)
 
   def show_popup_message(self, message, dialog={}, widget={}):
@@ -407,10 +405,16 @@
     }
     return identica_menu
     
-  def any_active_network(self):
-    return self.twitter.api or self.identica.api
+  def any_network_is_active(self):
+    return len(self.networks) > 0
+    
+  def update_active_networks(self):
+    if self.twitter.api:
+      self.networks.append(self.twitter)
+    if self.identica.api:
+      self.networks.append(self.identica)
         
-  def set_visual_for_active_networks(self):
+  def update_visual_for_active_networks(self):
     if self.twitter.api:
       self.icon.SetIcon(os.path.abspath("./icon"))                                  # overwrite the alert mark "!!!"
       if self.identica.api:
@@ -423,20 +427,19 @@
 
   def __init__(self):
     
-    # TODO: Rename class, and file
-    self.interface = Networks()
+    self.interface = Interface()
     
     self.twitter = self.interface.twitter()
     self.identica = self.interface.identica()
     
-    # self.networks = []  # self.twitter, self.identica
+    self.networks = []                                                                        # active networks
     
     (self.responding_screen_name, self.responding_authorization, self.responding_pin,
     self.responding_success, self.responding_tweet, self.responding_initial_informations,
     self.responding_sending_direct_message_reply, self.responding_retweet) = range(8)
     self.dialog_type = None
     
-    self.emblem = emblem.Emblem()                                                                       # emblem maker, see emblem.py
+    self.emblem = emblem.Emblem()                                                             # emblem maker, see emblem.py
 
     self.direct_messages_menu_id  = 1000
     self.credentials_menu_id      = 2000
@@ -462,7 +465,8 @@
     elif not self.identica.get_api():
       logm("User not found")
       self.show_inexistence_of_networks()   
-    self.set_visual_for_active_networks()
+    self.update_active_networks()
+    self.update_visual_for_active_networks()
 
   def get_config(self, keyfile):
     self.config['emblem_size'] = keyfile.get('Configuration', 'emblem_size')
@@ -502,7 +506,7 @@
     elif not self.message_stream.empty():
       self.show_new_direct_messages()
     else:
-      if self.any_active_network():
+      if self.any_network_is_active():
         self.ask_for_tweet()
 
   def on_middle_click(self):

=== modified file 'Twitter/Twitter.conf'
--- Twitter/Twitter.conf	2012-05-18 00:00:39 +0000
+++ Twitter/Twitter.conf	2012-05-20 13:03:18 +0000
@@ -1,4 +1,4 @@
-#0.4
+#0.4.1
 
 #[gtk-about]
 [Icon]

=== modified file 'Twitter/auto-load.conf'
--- Twitter/auto-load.conf	2012-05-18 00:00:39 +0000
+++ Twitter/auto-load.conf	2012-05-20 13:03:18 +0000
@@ -10,7 +10,7 @@
 category = 3
 
 # 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.
-version = 0.4
+version = 0.4.1
 
 # Whether the applet can be instanciated several times or not.
 multi-instance = true

=== modified file 'Twitter/identica.py'
--- Twitter/identica.py	2012-05-18 00:00:39 +0000
+++ Twitter/identica.py	2012-05-20 13:03:18 +0000
@@ -16,7 +16,7 @@
 #  GNU General Public License for more details.
 
 from oauth import oauth
-import urllib2, urllib
+import simplejson
 
 from network import Network
 from user import User
@@ -91,7 +91,8 @@
       self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
       self.access_token = oauth.OAuthToken(access_key, access_secret)
       
-      self.update_url = 'http://identi.ca/api/statuses/update.json'
+      self.update_url         = 'http://identi.ca/api/statuses/update.json'
+      self.home_timeline_url  = 'http://identi.ca/api/statuses/home_timeline.json'
 
     def dispatch(self, url, mode, parameters={}):
       oauth_request = oauth.OAuthRequest.from_consumer_and_token(self.consumer,
@@ -100,7 +101,6 @@
                                                                parameters = parameters,
                                                                http_method = mode)
       oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
-#      logp(oauth_request.to_url())
       if mode == "GET":
         url = oauth_request.to_url()
         response = get(url) 
@@ -111,3 +111,6 @@
 
     def tweet(self, message):                                                                 # popularly "send a tweet"
       self.dispatch(self.update_url, "POST", {'status':message})
+      
+    def home_timeline(self):
+      return self.dispatch(self.home_timeline_url, "GET")

=== added file 'Twitter/interface.py'
--- Twitter/interface.py	1970-01-01 00:00:00 +0000
+++ Twitter/interface.py	2012-05-20 13:03:18 +0000
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+
+# This is a part of the external Twitter applet for Cairo-Dock
+#
+# Author: Eduardo Mucelli Rezende Oliveira
+# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
+#
+# This program is free software: you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#  GNU General Public License for more details.
+
+class Interface:
+
+  def twitter(self):
+    from twitter import Twitter
+    return Twitter()
+  
+  def identica(self):
+    from identica import Identica
+    return Identica()

=== modified file 'Twitter/menu.py'
--- Twitter/menu.py	2012-03-22 00:14:49 +0000
+++ Twitter/menu.py	2012-05-20 13:03:18 +0000
@@ -28,7 +28,7 @@
         item.set_label(message.sender)                                                # used to track who sent the message in order to reply it.
       elif isinstance(message, Tweet):
         item.set_label(message.uid)                                                   # used to retweet the tweet
-      item.set_image(gtk.image_new_from_file(os.path.abspath("./data/message_small.png")))
+      item.set_image(gtk.image_new_from_file(os.path.abspath("./data/message_%s.png" % message.network)))
       text = "<b>%s</b>\n%s" % (message.sender, message.text)
       item.get_children()[0].set_markup(text)
       if self.callback:                                                               # for tweets posted by the user, there is not callback to be set

=== removed file 'Twitter/networks.py'
--- Twitter/networks.py	2012-05-13 00:58:06 +0000
+++ Twitter/networks.py	1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
-#!/usr/bin/python
-
-# This is a part of the external Twitter applet for Cairo-Dock
-#
-# Author: Eduardo Mucelli Rezende Oliveira
-# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
-#
-# This program is free software: you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation, either version 3 of the License, or
-#  (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-#  GNU General Public License for more details.
-
-class Networks:
-
-  def twitter(self):
-    from twitter import Twitter
-    return Twitter()
-  
-  def identica(self):
-    from identica import Identica
-    return Identica()


Follow ups