Module contacts

Source Code for Module contacts

  1  print('****************************************************************************'); 
  2  print('SkypeKit Python Wrapper Tutorial: Contacts and Online Status Events'); 
  3  print('****************************************************************************'); 
  4  
 
  5  # This example demonstrates, how to:
 
  6  # 1. Retrieve and display contact list
 
  7  # 2. Catch contact online appearance events.
 
  8  
 
  9  # NB! You will need to launch the SkypeKit runtime before running this example.
 
 10  
 
 11  #----------------------------------------------------------------------------------
 
 12  # Importing necessary libraries. Note that you will need to set the keyFileName value
 
 13  # in the keypair.py file.
 
 14  
 
 15  import sys; 
 16  import keypair; 
 17  from time import sleep; 
 18  
 
 19  sys.path.append(keypair.distroRoot + '/ipc/python'); 
 20  sys.path.append(keypair.distroRoot + '/interfaces/skype/python'); 
 21  
 
 22  try: 
 23          import Skype;    
 24  except ImportError: 
 25    raise SystemExit('Program requires Skype and skypekit modules'); 
 26  
 
 27  #----------------------------------------------------------------------------------
 
 28  # Taking skypename and password arguments from command-line.
 
 29  
 
 30  if len(sys.argv) != 3: 
 31          print('Usage: python contacts.py <skypename> <password>'); 
 32          sys.exit(); 
 33  
 
 34  accountName = sys.argv[1]; 
 35  accountPsw  = sys.argv[2]; 
 36  loggedIn        = False; 
 37  
 
 38  #----------------------------------------------------------------------------------
 
 39  # Creating our main Skype object
 
 40  
 
 41  try: 
 42          MySkype = Skype.GetSkype(keypair.keyFileName); 
 43          MySkype.Start(); 
 44  except Exception: 
 45          raise SystemExit('Unable to create Skype instance'); 
 46  
 
 47  #----------------------------------------------------------------------------------
 
 48  # Defining our own Account property change callback and assigning it to the
 
 49  # Skype.Account class.
 
 50  
 
51 -def AccountOnChange (self, property_name):
52 global loggedIn; 53 if property_name == 'status': 54 if self.status == 'LOGGED_IN': 55 loggedIn = True; 56 print('Login complete.');
57 58 Skype.Account.OnPropertyChange = AccountOnChange; 59 60 #---------------------------------------------------------------------------------- 61 # Defining our own Contact property change callback and assigning it to the 62 # SkyLib.Contact class. 63
64 -def ContactOnPropertyChange(self, property_name):
65 if property_name == 'availability': 66 print('Online status event: ' + self.displayname + ' is now ' + self.availability);
67 68 Skype.Contact.OnPropertyChange = ContactOnPropertyChange; 69 70 #---------------------------------------------------------------------------------- 71 # Retrieving account and logging in with it. 72 73 account = MySkype.GetAccount(accountName); 74 75 print('Logging in with ' + accountName); 76 account.LoginWithPassword(accountPsw, False, False); 77 78 while loggedIn == False: 79 sleep(1); 80 81 #---------------------------------------------------------------------------------- 82 # Retrieving contact list in two steps: 83 # 1. we need to get a CountactGroup object with MySkype.GetHardwiredContactGroup 84 # 2. then we need to get a contact list with ContactGroup.GetContacts 85 86 skypeContactGroup = MySkype.GetHardwiredContactGroup('SKYPE_BUDDIES'); 87 skypeContacts = skypeContactGroup.GetContacts(); 88 89 # Note that we are using SKYPE_BUDDIES filter here - which only includes skypename 90 # contacts - phone number contacts (PSTN) will not be included. The full list of 91 # 'Hardwired' filters is: 92 # ALL_KNOWN_CONTACTS 93 # ALL_BUDDIES 94 # SKYPE_BUDDIES 95 # SKYPEOUT_BUDDIES 96 # ONLINE_BUDDIES 97 # UNKNOWN_OR_PENDINGAUTH_BUDDIES 98 # RECENTLY_CONTACTED_CONTACTS 99 # CONTACTS_WAITING_MY_AUTHORIZATION 100 101 print('List of Skype contacts for this account: '); 102 for C in skypeContacts: 103 print(C.displayname); 104 105 # Note that at this point - immediately after the login - there is not much point 106 # to display contact online status. Online statuses will update themselves over 107 # over next couple of seconds. These events we will catch in ContactOnPropertyChange 108 109 print('Press ENTER to exit'); 110 raw_input(''); 111 print('Exiting..'); 112 MySkype.stop(); 113