← 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/106288

Twitter: Fully supporting individually account log-in. Code improvements, refactoring, and bug fixes.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Twitter/+merge/106288
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-13 00:58:06 +0000
+++ Twitter/ChangeLog	2012-05-18 00:04:23 +0000
@@ -1,3 +1,4 @@
+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.
 0.2.1: (March/22/2012): Added user timeline.

=== modified file 'Twitter/Twitter'
--- Twitter/Twitter	2012-05-13 00:58:06 +0000
+++ Twitter/Twitter	2012-05-18 00:04:23 +0000
@@ -27,10 +27,15 @@
 # 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: Change icon someway when Identi.ca is added.
+#       Try to fix someway that ugly hack "if not adding_identica:", dammit!
+#       Add more possibilties to the Identi.ca API
+
 import os, webbrowser, Queue
 
 from networks import Networks                                                   # networks.py
-from user import User                                                           # user.py
+from twitter import Twitter
+from identica import Identica
 import emblem, menu                                                             # emblem.py, menu.py
 from message import DirectMessage, Tweet                                        # message.py
 from util import *                                                              # util.py
@@ -55,7 +60,7 @@
       self.emblem.update(counter)                                                               # create the emblem with the counter
       self.icon.SetIcon(self.emblem.emblem)
     else:
-      self.icon.SetIcon(os.path.abspath("./icon"))  
+      self.set_visual_for_active_networks()
     
   def refresh_emblem_size(self):
     if self.config['emblem_size'] == "Small":
@@ -103,7 +108,7 @@
   def show_user_timeline(self):
     self.inform_start_of_waiting_process()
     
-    timeline = self.twitter_api.user_timeline()
+    timeline = self.twitter.api.user_timeline()
     if len(timeline) > 0:
       ut_menu = menu.Menu(self.icon)                                                        # callback not set since there is no action when clicking ...
       for status in timeline:                                                               # ... on the menu generated from this list
@@ -137,7 +142,7 @@
   def show_home_timeline(self):
     self.inform_start_of_waiting_process()
     
-    timeline = self.twitter_api.home_timeline()
+    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:
@@ -170,7 +175,7 @@
   def show_direct_messages(self):
     self.inform_start_of_waiting_process()
 
-    messages = self.twitter_api.direct_messages()
+    messages = self.twitter.api.direct_messages()
     if len(messages) > 0:
       dm_menu = menu.Menu(self.icon, self.on_direct_messages_list_menu_clicked)
       for status in messages:
@@ -191,14 +196,9 @@
   def on_tweet_list_menu_clicked(self, widget):
     self.ask_for_retweet(widget.get_label())                                        # label contains the id of the tweet needed to retweet it
 
-  def tweet(self, message):                                                         # popularly "send a tweet"
-    self.inform_start_of_waiting_process()
-    self.twitter_api.update_status(message)
-    self.inform_end_of_waiting_process()
-
   def show_credentials(self):
     self.inform_start_of_waiting_process()
-    credentials = self.twitter_api.verify_credentials()
+    credentials = self.twitter.api.verify_credentials()
     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'])
     dialog = {'use-markup':True}
     self.inform_end_of_waiting_process()
@@ -215,27 +215,29 @@
     
   def responding_sending_direct_message_reply(self, content):
     logp("Sending a direct message '%s'" % content)
-    self.twitter_api.new_direct_message(content, self.replying_direct_message_to)
+    self.twitter.api.new_direct_message(content, self.replying_direct_message_to)
 
   # Opens the dialog to be filled with the tweet and also informs about tweet longer than 140 characters
   def ask_for_tweet(self, default="", warning=False):
-    dialog = {'buttons':'ok;cancel'}
-    widget = {'widget-type':'text-entry', 'nb-chars':self.tweet_length + 1, 'initial-value':default}  # 140 characters max, a tweet :)
     if not warning:
-      message = _("%s, send a tweet") % self.twitter.user.screen_name
-      self.dialog_type = self.responding_tweet
+      message = _("%s, send a tweet" % (self.twitter.user.screen_name or self.identica.user.screen_name))
     else:                                                                                             # user entered more than 140 characters
       message = _("Your tweet has more than %d characters, please make it shorter") % self.tweet_length
-      self.dialog_type = self.responding_tweet
+    dialog = {'buttons':'ok;cancel'}
+    widget = {'widget-type':'text-entry', 'nb-chars':self.tweet_length + 1, 'initial-value':default}  # 140 characters max, a tweet :)
+    self.dialog_type = self.responding_tweet
     self.show_popup_message(message, dialog, widget)
     
   def responding_to_tweet(self, content):
     if len(content) > self.tweet_length:
       self.ask_for_tweet(content, warning=True)
     else:
-      logp("Sending a tweet '%s'" % content)
-      self.twitter_api.tweet(content)
-      self.identica_api.tweet(content)
+      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)
     
   def ask_for_retweet(self, tweet_id):
     dialog = {'buttons':'ok;cancel'}
@@ -245,16 +247,18 @@
     
   def responding_to_retweet(self):
     logp("Retweeting")
-    self.twitter_api.retweet(self.retweet_tweet_id)
+    self.twitter.api.retweet(self.retweet_tweet_id)
 
   # Dialogs for the initial wizard to authorize the user
   # Initial Information -> Ask for screen name (username) -> Ask for authorization (open browser) -> Insert PIN -> Succesful connected
+  
+  def show_inexistence_of_networks(self):
+    message = _("This applet supports Twitter, and Identi.ca.\nRight-click -> Add account -> Twitter.\nRight-click -> Add account -> Identi.ca.")
+    self.show_popup_message(message)
 
   def show_initial_informations(self):
-    if not self.adding_identica:
-      message = _("Twitter Applet needs your nickname, and an authorization\nthat you accept it to connect on your Twitter account")
-    else:
-      message = _("Identi.ca Applet needs your nickname, and an authorization\nthat you accept it to connect on your Identi.ca account")
+    name = camelcase(self.new_network.name)
+    message = _("%s Applet needs your nickname, and an authorization\nthat you accept it to connect on your %s account" % (name, name))
     dialog = {'buttons':'next'}
     self.show_popup_message(message, dialog)
     self.dialog_type = self.responding_initial_informations
@@ -263,10 +267,7 @@
     self.ask_for_screen_name()
 
   def ask_for_screen_name(self):
-    if not self.adding_identica:
-      message = _("What is your Twitter nickname?")
-    else:
-      message = _("What is your Identi.ca nickname?")
+    message = _("What is your %s nickname?" % camelcase(self.new_network.name))
     dialog = {'buttons':'next'}
     widget = {'widget-type':'text-entry'}
     self.show_popup_message(message, dialog, widget)
@@ -274,27 +275,19 @@
 
   def responding_to_screen_name(self, content):
     logp("Receiving screen name '%s'" % content)
-    if not self.adding_identica:
-      self.twitter.user.screen_name = content
-    else:
-      self.identica.user.screen_name = content
+    self.new_network.user.screen_name = content
     self.ask_for_authorization()
 
   def ask_for_authorization(self):
-    if not self.adding_identica:
-      authorization_url = self.twitter_auth.get_authorization_url()
-      network = "Twitter"
-    else:
-      authorization_url = self.identica_auth.get_authorization_url()
-      network = "Identi.ca"
+    authorization_url = self.new_network.auth.get_authorization_url()
     logp("Opening the auth URL '%s'" % authorization_url)
     dialog = {'buttons':'next'}
     try:
       webbrowser.open(authorization_url)
-      message = _("%s 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 go to the next dialog" % network)
+      message = _("%s 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 go to the next dialog" % camelcase(self.new_network.name))
       self.show_popup_message(message, dialog)
     except webbrowser.Error:    
-      message = _("%s 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" % network)
+      message = _("%s 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" % camelcase(self.new_network.name))
       widget = {'widget-type':'text-entry', 'initial-value':authorization_url}
       self.show_popup_message(message, dialog, widget)
     self.dialog_type = self.responding_authorization
@@ -312,24 +305,15 @@
     
   def responding_to_pin(self, content):
     logp("Receiving PIN: %s" % content)
-    if not self.adding_identica:
-      self.twitter.user.access_key, self.twitter.user.access_secret = self.twitter_auth.get_access_token_and_secret(content)
-      logp("Writing user data")
-      self.twitter.user.write()                                                           # writing user's access token and access secret to be ...
-      self.twitter_api = self.twitter.get_api(self.on_receive_new_entry_into_stream_callback)     # ... used here, check twitter.py method get_api
-      if self.twitter_api:
+    self.new_network.user.access_key, self.new_network.user.access_secret = self.new_network.auth.get_access_token_and_secret(content)
+    self.new_network.user.write()                                                               # writing user's access token and access secret to be ...
+    if isinstance(self.new_network, Twitter):
+      if self.new_network.get_api(self.on_receive_new_entry_into_stream_callback):              # ... used here, check twitter.py method get_api
         self.show_popup_message(_("Successfully connected with Twitter"))
-      else:
-        logm("A problem has occurred while getting access to Twitter API")
     else:
-      self.identica.user.access_key, self.identica.user.access_secret = self.identica_auth.get_access_token_and_secret(content)
-      logp("Writing user data")
-      self.identica.user.write()                                                           # writing user's access token and access secret to be ...
-      self.identica_api = self.identica.get_api()                                          # ... used here, check identica.py method get_api
-      if self.identica_api:
+      if self.new_network.get_api():                                                            # ... used here, check identica.py method get_api
         self.show_popup_message(_("Successfully connected with Identi.ca"))
-      else:
-        logm("A problem has occurred while getting access to the Identi.ca API")
+    self.set_visual_for_active_networks()
 
   def show_popup_message(self, message, dialog={}, widget={}):
     dialog_attributes = {'message':message}
@@ -388,70 +372,96 @@
         'icon'  : os.path.abspath("./data/tweet.png")
     })
     self.icon.AddMenuItems(user_timeline_menu)
-    
-  def build_identica_menu(self):
-    identica_menu = []
-    menu = {
+
+  def build_add_twitter_and_identica_account_menus(self):
+    self.icon.AddMenuItems([self.build_add_account_menu(),self.build_add_twitter_account_menu(),self.build_add_identica_account_menu()])
+    
+  def build_add_only_twitter_account_menu(self):
+    self.icon.AddMenuItems([self.build_add_account_menu(),self.build_add_twitter_account_menu()])
+    
+  def build_add_only_identica_account_menu(self):
+    self.icon.AddMenuItems([self.build_add_account_menu(),self.build_add_identica_account_menu()])
+
+  def build_add_account_menu(self):
+    add_account_menu = {
         'type'  : CDApplet.MENU_SUB_MENU,
+        'label' : _("Add account"),
+        'id'    : self.add_account_menu_id
+    }
+    return add_account_menu
+
+  def build_add_twitter_account_menu(self):
+    twitter_menu = {
+        'type'  : CDApplet.MENU_ENTRY,
+        'label' : _("Twitter"),
+        'id'    : self.add_twitter_account_menu_id,
+        'icon'  : os.path.abspath("./data/twitter.png"),
+        'menu'  : self.add_account_menu_id
+    }
+    return twitter_menu
+
+  def build_add_identica_account_menu(self):
+    identica_menu = {
+        'type'  : CDApplet.MENU_ENTRY,
         'label' : _("Identi.ca"),
-        'id'    : self.identica_menu_id,
-        'icon'  : os.path.abspath("./data/identica.png")
-    }
-    sub_menu = {
-        'type'  : CDApplet.MENU_ENTRY,
-        'label' : _("Add"),
-        'id'    : self.add_identica_menu_id,
-        'menu'  : self.identica_menu_id
-    }
-    identica_menu.append (menu)
-    identica_menu.append (sub_menu)
-    self.icon.AddMenuItems(identica_menu)
+        'id'    : self.add_identica_account_menu_id,
+        'icon'  : os.path.abspath("./data/identica.png"),
+        'menu'  : self.add_account_menu_id
+    }
+    return identica_menu
+    
+  def set_visual_for_active_networks(self):
+    if self.twitter.api:
+      if self.identica.api:
+        self.icon.SetLabel("Twitter and Identi.ca")
+        self.icon.SetIcon(os.path.abspath("./data/twitter_and_identica.png"))
+    else:
+      if self.identica.api:
+        self.icon.SetLabel("Identi.ca")
+        self.icon.SetIcon(os.path.abspath("./data/identica.png"))
 
   def __init__(self):
     
-    self.networks = Networks()
-    
-    self.twitter = self.networks.twitter()
-    self.twitter_auth = self.twitter.Oauth()
-    self.twitter_api = None
-
-    self.identica = self.networks.identica()
-    self.identica_auth = self.identica.Oauth()
-    self.identica_api = None
-    self.adding_identica = False
+    # TODO: Rename class, and file
+    self.interface = Networks()
+    
+    self.twitter = self.interface.twitter()
+    self.identica = self.interface.identica()
+    
+    # self.networks = []  # self.twitter, self.identica
     
     (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
     self.tweets_menu_id           = 3000
     self.user_timeline_menu_id    = 4000
-    self.identica_menu_id         = 5000
-    self.add_identica_menu_id     = 5001
+    
+    self.add_account_menu_id              = 5000
+    self.add_identica_account_menu_id     = 5001
+    self.add_twitter_account_menu_id      = 5002
     
     self.tweet_length             = 140
     
     self.tweet_stream   = Queue.Queue()
     self.message_stream = Queue.Queue()
 
-    CDApplet.__init__(self)                                                                           # call CDApplet interface init
+    CDApplet.__init__(self)                                                                             # call CDApplet interface init
 
   # Inherited methods from CDApplet
   def begin(self):
     logp("Looking for user ...")
-    if self.twitter.user.read():                                                                      # first time for the user
-      logp("User '%s' found" % self.twitter.user.screen_name)
-      self.twitter_api = self.twitter.get_api(self.on_receive_new_entry_into_stream_callback)         # pass stream api callback, kind of ugly it yet
-      if self.identica.user.read():
-        self.identica_api = self.identica.get_api()
-    else:                                                                                             # user not found
+    if self.twitter.get_api(self.on_receive_new_entry_into_stream_callback):                            # pass stream api callback, ugly yet!
+      self.identica.get_api()
+    elif not self.identica.get_api():
       logm("User not found")
-      self.show_initial_informations()                                                                # start the wizard
+      self.show_inexistence_of_networks()   
+    self.set_visual_for_active_networks()
 
   def get_config(self, keyfile):
     self.config['emblem_size'] = keyfile.get('Configuration', 'emblem_size')
@@ -497,12 +507,20 @@
     self.show_home_timeline()
 
   def on_build_menu(self):
-    self.build_credentials_menu()
-    self.build_user_timeline_menu()
-    self.build_direct_messages_menu()
-    self.build_tweets_menu()
-    if not self.identica_api:
-      self.build_identica_menu()
+    if self.twitter.api:
+      self.build_credentials_menu()
+      self.build_user_timeline_menu()
+      self.build_direct_messages_menu()
+      self.build_tweets_menu()
+      if self.identica.api:
+        logp("All accounts added")
+      else:
+        self.build_add_only_identica_account_menu()
+    else:
+      if self.identica.api:
+        self.build_add_only_twitter_account_menu()
+      else:
+        self.build_add_twitter_and_identica_account_menus()  
 
   def on_menu_select(self, selected_menu):
     if selected_menu == self.direct_messages_menu_id:
@@ -519,8 +537,11 @@
         self.show_new_tweets()                                                        # show new tweets
     elif selected_menu == self.user_timeline_menu_id:
       self.show_user_timeline()
-    elif selected_menu == self.add_identica_menu_id:
-      self.adding_identica = True
+    elif selected_menu == self.add_identica_account_menu_id:
+      self.new_network = self.identica
+      self.show_initial_informations()
+    elif selected_menu == self.add_twitter_account_menu_id:
+      self.new_network = self.twitter
       self.show_initial_informations()
 
 if __name__ == '__main__':

=== modified file 'Twitter/Twitter.conf'
--- Twitter/Twitter.conf	2012-05-13 00:58:06 +0000
+++ Twitter/Twitter.conf	2012-05-18 00:04:23 +0000
@@ -1,4 +1,4 @@
-#0.3
+#0.4
 
 #[gtk-about]
 [Icon]

=== modified file 'Twitter/auto-load.conf'
--- Twitter/auto-load.conf	2012-05-13 00:58:06 +0000
+++ Twitter/auto-load.conf	2012-05-18 00:04:23 +0000
@@ -4,13 +4,13 @@
 author = Eduardo Mucelli Rezende Oliveira
 
 # A short description of the applet and how to use it.
-description = You can send tweets, direct messages, and see your timeline. It will alert you when there are new directed messages, and new tweets.\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.\nYou can retweet any of them by left-clicking on it.\nTo 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.\nTo see some user's info right-click on the icon -> Twitter -> Info.
+description = This applet supports both Twitter, and Identi.ca. You can send tweets, direct messages, see your timeline, retweet, and answer direct messages. It will alert you when there are new tweets, and directed messages.\nOn the first time, you need to choose which network to add, once at a time by right-click -> Add account -> Twitter or Identi.ca. The applet is going to ask your nickname and authorization to connect on the networks.\nThe network authorization page will be open.\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.
 
 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
 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.3
+version = 0.4
 
 # Whether the applet can be instanciated several times or not.
 multi-instance = true

=== added file 'Twitter/data/twitter.png'
Binary files Twitter/data/twitter.png	1970-01-01 00:00:00 +0000 and Twitter/data/twitter.png	2012-05-18 00:04:23 +0000 differ
=== added file 'Twitter/data/twitter_and_identica.png'
Binary files Twitter/data/twitter_and_identica.png	1970-01-01 00:00:00 +0000 and Twitter/data/twitter_and_identica.png	2012-05-18 00:04:23 +0000 differ
=== modified file 'Twitter/identica.py'
--- Twitter/identica.py	2012-05-13 00:58:06 +0000
+++ Twitter/identica.py	2012-05-18 00:04:23 +0000
@@ -18,24 +18,27 @@
 from oauth import oauth
 import urllib2, urllib
 
+from network import Network
 from user import User
 from http import post, get
 from util import *
 
-class Identica:
+class Identica(Network):
   def __init__(self):
-    self.name = "identica"
+    Network.__init__(self, "identica")
     self.user = User(network=self.name)
+    self.auth = self.Oauth()
+    self.api = None
     
   def get_api(self):
-    if self.user_exists():
+    if self.user.exists():
+      logp("User '%s' found for Identi.ca" % self.user.screen_name)
       logp("Getting Identi.ca API")
-      return self.IdenticaAPI(self.user.access_key, self.user.access_secret)
+      self.api = self.IdenticaAPI(self.user.access_key, self.user.access_secret)
+      return True
     else:
+      logm("A problem has occurred while getting access to Identi.ca API")
       return False
-      
-  def user_exists(self):
-    return self.user.access_secret and self.user.access_secret
     
   class Oauth:
     def __init__(self):
@@ -87,9 +90,6 @@
       consumer_key, consumer_secret = read_consumer_key_and_secret("identica")
       self.consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)
       self.access_token = oauth.OAuthToken(access_key, access_secret)
-      print "=================="
-      print self.access_token
-      print "=================="
       
       self.update_url = 'http://identi.ca/api/statuses/update.json'
 
@@ -100,7 +100,7 @@
                                                                parameters = parameters,
                                                                http_method = mode)
       oauth_request.sign_request(self.signature_method, self.consumer, self.access_token)
-      print oauth_request.to_url()
+#      logp(oauth_request.to_url())
       if mode == "GET":
         url = oauth_request.to_url()
         response = get(url) 

=== added file 'Twitter/network.py'
--- Twitter/network.py	1970-01-01 00:00:00 +0000
+++ Twitter/network.py	2012-05-18 00:04:23 +0000
@@ -0,0 +1,20 @@
+#!/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 Network:
+  def __init__(self, name):
+    self.name = name

=== modified file 'Twitter/twitter.py'
--- Twitter/twitter.py	2012-05-13 00:58:06 +0000
+++ Twitter/twitter.py	2012-05-18 00:04:23 +0000
@@ -18,27 +18,29 @@
 from oauth import oauth
 import simplejson, threading, urllib2
 
+from network import Network
 from user import User
 from http import post, get #, stream
 from util import *
 
-class Twitter:
+class Twitter(Network):
   def __init__(self):
-    self.name = "twitter"
+    Network.__init__(self, "twitter")
     self.user = User(network=self.name)
+    self.auth = self.Oauth()
+    self.api = None
     
   def get_api(self, stream_api_callback):
-    # start StreamAPI and return the instance of TwitterAPI
-    if self.user_exists():
+    if self.user.exists():
+      logp("User '%s' found for Twitter" % self.user.screen_name)
       logp("Getting Twitter API")
       self.TwitterStreamAPI(self.user.access_key, self.user.access_secret, stream_api_callback)
-      return self.TwitterAPI(self.user.access_key, self.user.access_secret)
+      self.api = self.TwitterAPI(self.user.access_key, self.user.access_secret)
+      return True
     else:
+      logm("A problem has occurred while getting access to Twitter API")
       return False
       
-  def user_exists(self):
-    return self.user.access_secret and self.user.access_secret
-  
   class Oauth():
     def __init__(self):
       self.request_token_url  = 'https://twitter.com/oauth/request_token'

=== modified file 'Twitter/user.py'
--- Twitter/user.py	2012-05-13 00:58:06 +0000
+++ Twitter/user.py	2012-05-18 00:04:23 +0000
@@ -17,13 +17,16 @@
 
 import os
 
+from util import *
+
 class User:
   def __init__(self, screen_name="", access_key="", access_secret="", network="twitter"):
     self.screen_name = screen_name
     self.access_key = access_key
     self.access_secret = access_secret
-    self.user_file = os.path.abspath(os.path.join(os.getcwd(),'..','..','.%s_users' % network))      # ~/.config/cairo-dock/.twitter_users
-    
+    self.network = network
+    self.user_file = os.path.abspath(os.path.join(os.getcwd(),'..','..','.%s_users' % self.network))      # ~/.config/cairo-dock/.twitter_users
+  
   # TODO: Implement it as a config file using screen_name as section index
   def read(self):
     """Read the users file formated as Screen Name<space>Access Key<space>Access Secret"""
@@ -32,13 +35,17 @@
       if os.path.getsize(self.user_file) > 0:
         f = open(self.user_file, "rb")
         data = f.read()
-        self.screen_name, self.access_key, self.access_secret = data.split()                    # split the line by space token
+        self.screen_name, self.access_key, self.access_secret = data.split()                              # split the line by space token
         f.close()
         found = True
     return found
 
   def write(self):
+    logp("Writing user data for %s" % self.network)
     f = open(self.user_file, 'w')
     f.write("%s %s %s" % (self.screen_name, self.access_key, self.access_secret))
     f.close()
+    
+  def exists(self):
+    return self.read()
 

=== modified file 'Twitter/util.py'
--- Twitter/util.py	2012-05-13 00:58:06 +0000
+++ Twitter/util.py	2012-05-18 00:04:23 +0000
@@ -18,10 +18,14 @@
 import ConfigParser
 
 def logp (string):
-    print "[+] Twitter: %s" % string
+  print "[+] Twitter: %s" % string
 
 def logm (string):
-    print "[-] Twitter: %s" % string
+  print "[-] Twitter: %s" % string
+
+def camelcase(string):
+  """ capitalizes only first character of a string """
+  return string[0].capitalize() + string[1:]
 
 # Read the user's consumer key and secret necessary for the requests
 def read_consumer_key_and_secret(network="twitter"):
@@ -32,11 +36,3 @@
     return config.get(network, 'consumer_key'), config.get(network, 'consumer_secret')
   except configparser.Error:
     logm("It was not possible to read the consumer key and secret for '%s', check the .keys.cgf file" % network)
-#		try:
-#			f = open('.keys')
-#			data = f.read()
-#			f.close()
-#		except IOError:
-#			logm("It was not possible to read the consumer key and secret, check the .keys file")
-#		else:
-#			return data.split()


Follow ups