Module conversations

Source Code for Module conversations

 1  print('****************************************************************************'); 
 2  print('SkypeKit Python Wrapper Tutorial: Retrieving Inbox Conversation List'); 
 3  print('****************************************************************************'); 
 4  
 
 5  # This example demonstrates, how to:
 
 6  # 1. Log in and retrieve a list of conversations.
 
 7  
 
 8  # NB! You will need to launch the SkypeKit runtime before running this example.
 
 9  
 
10  #----------------------------------------------------------------------------------
 
11  # Importing necessary libraries. Note that you will need to set the keyFileName value
 
12  # in the keypair.py file.
 
13  
 
14  import sys; 
15  import keypair; 
16  from time import sleep; 
17  
 
18  sys.path.append(keypair.distroRoot + '/ipc/python'); 
19  sys.path.append(keypair.distroRoot + '/interfaces/skype/python'); 
20  
 
21  try: 
22          import Skype; 
23  except ImportError: 
24    raise SystemExit('Program requires Skype and skypekit modules'); 
25  
 
26  #----------------------------------------------------------------------------------
 
27  # Taking skypename and password arguments from command-line.
 
28  
 
29  if len(sys.argv) != 3: 
30          print('Usage: python conversations.py <skypename> <password>'); 
31          sys.exit(); 
32  
 
33  accountName = sys.argv[1]; 
34  accountPsw  = sys.argv[2]; 
35  loggedIn        = False; 
36  
 
37  #----------------------------------------------------------------------------------
 
38  # Creating our main Skype object
 
39  
 
40  try: 
41          MySkype = Skype.GetSkype(keypair.keyFileName); 
42          MySkype.Start(); 
43  except Exception: 
44          raise SystemExit('Unable to create Skype instance'); 
45  
 
46  #----------------------------------------------------------------------------------
 
47  # Defining our own Account property change callback and assigning it to the
 
48  # SkyLib.Account class.
 
49  
 
50 -def AccountOnChange (self, property_name):
51 global loggedIn; 52 if property_name == 'status': 53 if self.status == 'LOGGED_IN': 54 loggedIn = True; 55 print('Login complete.');
56 57 Skype.Account.OnPropertyChange = AccountOnChange; 58 59 #---------------------------------------------------------------------------------- 60 # Retrieving account and logging in with it. 61 62 account = MySkype.GetAccount(accountName); 63 64 print('Logging in with ' + accountName); 65 account.LoginWithPassword(accountPsw, False, False); 66 67 while loggedIn == False: 68 sleep(1); 69 70 71 # In this case will retrieve a list of recently active conversations (inbox) 72 convList = MySkype.GetConversationList('INBOX_CONVERSATIONS'); 73 # Other possible filter values are: 74 # 'ALL_CONVERSATIONS' 75 # 'BOOKMARKED_CONVERSATIONS' 76 # 'LIVE_CONVERSATIONS' 77 78 print('Found ' + str(len(convList)) + ' conversations.'); 79 N = 1; 80 for c in convList: 81 unread = c.unconsumed_suppressed_messages + c.unconsumed_normal_messages + c.unconsumed_elevated_messages; 82 print(str(N) + '. ' + c.displayname + ' (type = ' + c.type + ') unread messages: ' + str(unread)); 83 N = N + 1; 84 85 raw_input('Press ENTER to continue'); 86 print('Exiting..'); 87 MySkype.stop(); 88