Module login

Source Code for Module login

 1  print('****************************************************************************'); 
 2  print('SkypeKit Python Wrapper Tutorial: Account Login'); 
 3  print('****************************************************************************'); 
 4  
 
 5  # This examle demonstrates, how to:
 
 6  # 1. Create a Skype instance with the Python wrapper.
 
 7  # 2. Retrieve an Account class instance.
 
 8  # 3. Assign a custom callback to Account class, to detect login status.
 
 9  # 4. Log in with that account.
 
10  
 
11  # NB! You will need to launch the SkypeKit runtime before running this example.
 
12  
 
13  #----------------------------------------------------------------------------------
 
14  # Importing necessary libraries. Note that you will need to set the keyFileName value
 
15  # in the keypair.py file.
 
16  
 
17  import sys; 
18  import keypair; 
19  from time import sleep; 
20  
 
21  sys.path.append(keypair.distroRoot + '/ipc/python'); 
22  sys.path.append(keypair.distroRoot + '/interfaces/skype/python'); 
23  
 
24  try: 
25          import Skype; 
26  except ImportError: 
27      raise SystemExit('Program requires Skype and skypekit modules') 
28  
 
29  #----------------------------------------------------------------------------------
 
30  # Taking skypename and password arguments from command-line.
 
31  
 
32  if len(sys.argv) != 3: 
33          print('Usage: python login1.py <skypename> <password>'); 
34          sys.exit(); 
35  
 
36  accountName = sys.argv[1]; 
37  accountPsw  = sys.argv[2]; 
38  loggedIn        = False; 
39  
 
40  #----------------------------------------------------------------------------------
 
41  # Creating our main Skype object
 
42  
 
43  try: 
44          MySkype = Skype.GetSkype(keypair.keyFileName); 
45          MySkype.Start(); 
46  except Exception: 
47          raise SystemExit('Unable to create Skype instance') 
48  
 
49  #----------------------------------------------------------------------------------
 
50  # Defining our own Account property change callback and assigning it to the
 
51  # SkyLib.Account class.
 
52  
 
53 -def AccountOnChange (self, property_name):
54 global loggedIn; 55 if property_name == 'status': 56 print ('Login sequence: ' + self.status); 57 if self.status == 'LOGGED_IN': 58 loggedIn = True; 59 if self.status == 'LOGGED_OUT': 60 loggedIn = False;
61 62 Skype.Account.OnPropertyChange = AccountOnChange; 63 64 #---------------------------------------------------------------------------------- 65 # Retrieving account and logging in with it. 66 67 account = MySkype.GetAccount(accountName); 68 69 print('Logging in with ' + accountName); 70 account.LoginWithPassword(accountPsw, False, False); 71 72 while not loggedIn: 73 sleep(1); 74 75 print('You should now be able to see this account as online from other Skype instances.'); 76 raw_input('Press ENTER to log out'); 77 print('Exiting..'); 78 MySkype.stop(); 79