From cee3ab8897af4e6d9d68a635ea6b5580dec48fd9 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 20 Apr 2010 14:04:13 -0400 Subject: [PATCH] Added support for account sections in config file... multiple account sections are supported. Currently, only the first one is used. --- TODO | 1 + mytwitter.py | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index c6314c6..92c7705 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,4 @@ This is a list of things that still need doing. It includes short-, medium-, an * Add a graphical options menu * Support some kind of 'conversation' view for in-reply-to chains, instead of the standard single-tweet * Come up with a better bloody name +* Status bar icon diff --git a/mytwitter.py b/mytwitter.py index 8c0902d..076e22f 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -16,8 +16,19 @@ class MyTwitter(): def __init__(self, config_file): config = ConfigParser.ConfigParser() config.read(os.path.expanduser(config_file)) - self.username = config.get('global', 'username') - self.password = config.get('global', 'password') + + self.accounts = [] + for item in config.sections(): + if (re.match(r'account-', item)): + account_name = re.sub(r'account-', '', item) + self.accounts.append({'account_name': account_name, + 'username': config.get(item, 'username'), + 'api': twitter.Api(username=config.get(item, 'username'), password=config.get(item, 'password')) + }) + + self.username = self.accounts[0]['username'] + self.api = self.accounts[0]['api'] + self.num_entries = int(config.get('global', 'entries')) self.refresh_time = int(config.get('global', 'refreshtime')) @@ -32,9 +43,6 @@ class MyTwitter(): self.reply_id = None - # Authenticate with twitter, set up the API object - self.api = twitter.Api(username=self.username, password=self.password) - # Load up all the GUI stuff self.init_user_interface('./default.glade') self.init_widgets() @@ -56,11 +64,16 @@ class MyTwitter(): self.following_button = self.widget_tree.get_widget('following_button') self.at_button = self.widget_tree.get_widget('at_button') self.verified_label = self.widget_tree.get_widget('verified_label') + self.account_select = self.widget_tree.get_widget('account_select') self.context_id = self.status_bar.get_context_id('message') self.tweet_notebook.remove_page(0) # kill the page that glade makes us have + # Add entries to the account select box +# for account in self.accounts: +# self.account_select. + # When we change tabs, any unread tweets in it become read self.tweet_notebook.connect('switch_page', self.on_tab_change)