Advertisement
six519

Untitled

Nov 22nd, 2011
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. import sha
  2. from time import gmtime, strftime
  3. import urllib2, urllib
  4.  
  5.  
  6. def getTPSTimeString():
  7.    
  8.     return strftime("%Y%m%d%H%M",gmtime())[0:11]
  9.  
  10. def voucher_catalogue(str_timestamp = None):
  11.    
  12.     voucherServer = 'http://tct-testing-tps.hk.kitesystems.com:8080/voucher-testing2/api/catalogue'    
  13.    
  14.     sha1 = sha.new()
  15.     if str_timestamp is not None:
  16.         sha1.update(str(str_timestamp))
  17.     else:
  18.         sha1.update(str(""))
  19.        
  20.     sha1.update('WALLET_TO_VOUCHER')
  21.     sha1.update('492DDE365315631F')
  22.     sha1.update(str(getTPSTimeString()))
  23.    
  24.    
  25.     cat_request = CatalogueRequest()
  26.    
  27.     if str_timestamp is not None:
  28.         cat_request.timestamp = str_timestamp
  29.     else:
  30.         cat_request.timestamp = ""
  31.  
  32.     cat_request.appName = 'WALLET_TO_VOUCHER'
  33.     cat_request.sessionControl = str(sha1.hexdigest())
  34.  
  35.     try:
  36.         urllib_request = urllib2.Request(voucherServer,cat_request.SerializeToString())
  37.         response = urllib2.urlopen(urllib_request).read()
  38.  
  39.         catalogue = Catalogue()
  40.         catalogue.ParseFromString(response)
  41.        
  42.         if not catalogue.success:
  43.             return False
  44.         else:
  45.             return catalogue
  46.     except Exception as e:
  47.         return False
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement