mhammond's skype patch
authorMark Hammond <mhammond@skippinet.com.au>
Mon, 23 Feb 2009 06:26:40 -0800
changeset 53 5f05251057e9c4a418e7da9239d484e3f3111508
parent 50 238424d64ec4a461900591110e51b12dc81257db
child 54 e65d990ada6a8ff9bca749ec82b96d719c83344b
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
mhammond's skype patch
server/python/junius/bootstrap.py
--- a/server/python/junius/bootstrap.py
+++ b/server/python/junius/bootstrap.py
@@ -34,26 +34,61 @@ def setup_account(dbs):
 
 def setup_twitter_account(dbs):
     # we want a file of the form:
     #  username,password
     # example:
     #  davidascher,sekret
     import os, os.path
     configPath = os.path.join(os.environ['HOME'], ".junius_twitter")
+    if not os.path.isfile(configPath):
+        print "Skipping twitter - no config file '%s'" % (configPath,)
+        return
     f = open(configPath, 'r')
     data = f.read()
     f.close()
     username, password = data.split(',')
 
     account = model.Account(
         kind='twitter', username=username, password=password,
     )
     account.store(dbs.accounts)
 
+def setup_skype_account(dbs):
+    # For now we just use whoever is currently logged into skype (but we
+    # probably do want a config file and should skip things if that user
+    # isn't current.)
+
+    # XXX - paramaterized views?
+    accts = [acct for acct in model.Account.all(dbs.accounts) if acct.kind=='skype']
+    if accts:
+        print 'Skype accounts for %r already exist, not automatically adding a new one!' % \
+              [acct.username for a in accts]
+        return
+
+    try:
+        import Skype4Py
+    except ImportError:
+        print "skipping skype as the Skype4Py module isn't installed"
+    else:
+        skype = Skype4Py.Skype()
+        skype.Timeout = 10000 # default of 30 seconds is painful...
+        print 'Connecting to Skype (please check skype; you may need to authorize us)'
+        try:
+            skype.Attach()
+        except Skype4Py.SkypeAPIError, exc:
+            print 'Failed to attach to Skype (is it installed and running? Is authorization pending?)'
+            print '  error was:', exc
+            return
+        print 'Creating skype account for current user', skype.CurrentUser.Handle
+        account = model.Account(
+            kind='skype', username=skype.CurrentUser.Handle,
+        )
+        account.store(dbs.accounts)
+
 def path_part_nuke(path, count):
     for i in range(count):
         path = os.path.dirname(path)
     return path
     
 
 FILES_DOC = 'files' #'_design/files'
 
@@ -93,13 +128,14 @@ def main():
     if 'nuke' in sys.argv:
       print 'NUKING DATABASE!!!'
       model.nuke_db()
 
     dbs = model.fab_db(update_views='updateviews' in sys.argv)
 
     setup_account(dbs)
     setup_twitter_account(dbs)
+    setup_skype_account(dbs)
     install_client_files(dbs)
     
 
 if __name__ == '__main__':
     main()