MastaKay's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
8 (0 per day)
Joined:
12-November 07
Profile Views:
287
Last Active:
User is offline Jan 25 2012 12:22 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
Dream Kudos:
0

Latest Visitors

  • PhotoMotoma Icon
    24 Jan 2012 - 06:50
Icon   MastaKay has not set their status

Posts I've Made

  1. In Topic: HTTP requests using Python

    Posted 24 Jan 2012

    Thank you Motoma....I have been playing around with httplib, httplib2, and urllib, urllib2 but not winning....I will post my latest code shortly...I do not need anything from the page. I just need to update the "getdir" field and the "cobdate" field then submit
  2. In Topic: TypeError: not all arguments converted during string formatting

    Posted 24 Nov 2011

    I have just amended the code slightly and it seems the covertion is no longer a problem. The problem now is picking the files and sending them to the server. I can find the files but I still get "There are no files message"
    Thank you in advance
    import logging
    from ESSImporter_client import *
    from ESSImporter_types import *
    import os
    import datetime
    import time
    import sys
    import subprocess
    import paramiko
    import platform
    import string
    
    WSDESCRIPTOR = 'ESSImporter'
    LOGFILE = 'C:/Logs/%s/%s_%s.log' % (WSDESCRIPTOR.lower(), WSDESCRIPTOR, datetime.datetime.now().strftime("%Y-%m-%d"))
    TIBCOSERVER = 'GenevaServer'
    TIBCOPORT = '7979'
    WEBSERVICEADDRESS = "http://%(server)s:%(port)s/ESSImporter/Services/Interface/intfESSImporter-service.serviceagent/intfwsProcess_ESSImporterEndpoint1" % {'server': TIBCOSERVER, 'port': TIBCOPORT, 'ws': WSDESCRIPTOR}
    FILEPATH="C:/ESSSWAP/Archive/Ess_Import/"
    REMOTEPATH='/export/home/geneva/geneva-4000/extracts/out/%s'
    FTPSERVER = 'GenevaServer'
    FTPUSER = 'geneva'
    if platform.system().upper() == 'WINDOWS' : #dev environment
       FTPPASSWORD = "C:/Scripts/Python/certs/GENEVA/Priv_Key.ppk"
    else:
        FTPPASSWORD = "/export/home/geneva/geneva-4000/certs/GENEVA/Priv_Key.ppk"
    
    FILEEXT = string.replace(sys.argv[1], '-', '')
    FILELIST = ('basket_div_SA.0', 'basket_payment_SA.0', 'basket_summary_SA.0', 'basket_swap_SA.0', 'basket_trade_SA.0', 'interest_detail_SA.0', 'unwind_SA.0')
    for fileentry in FILELIST:
        filename = FILEPATH + fileentry + "." + FILEEXT
        if os.path.isfile(filename):        
            print 'file exists: ' + filename
        else:
            print 'no such file: ' + filename
     
    def getfile(ftphost, fromfile, tofile, tibcoinstanceInfo=None, tibcoinstanceError=None):
        
        if tibcoinstanceInfo:
            tibcoinstanceInfo('Connecting to %s as %s with pw %s' % (ftphost, FTPUSER, FTPPASSWORD))
            
        try:
            t = paramiko.Transport((ftphost, 22))
            key = paramiko.RSAKey.from_private_key_file(FTPPASSWORD)
            t.connect(username=FTPUSER, pkey=key)
            sftp = paramiko.SFTPClient.from_transport(t)
            
            if sftp != None:
                sftp.get(fromfile, tofile)
    
                sftp.close()
            
                if tibcoinstanceInfo:
                    tibcoinstanceInfo('FTP of the file was successful')
                result = True
            else:
                if tibcoinstanceError:
                    tibcoinstanceError('Could not connect to the FTP server')
                result = False
            
            
        except Exception, e:
            if tibcoinstanceError:
                tibcoinstanceError('Error FTPing the file from %s to %s: %s: %s' % (fromfile,tofile,e.__class__, e))
            result = False
            
        return result
    
    
    class TibcoWS():
        def __init__ (self, logfile, debuglevel, logmsg):
            if logfile:
                self.SetLogFile(logfile, debuglevel)
                if logmsg is not None:
                    logging.info(logmsg)
    
        def SetLogFile(self,fname,DebugLevel):
            
            path, filename = os.path.split(fname)
            self.makedir(path)
            logging.basicConfig(level=DebugLevel,
                format='%(asctime)s %(levelname)s %(message)s',
                filename=fname,
                filemode='a')
        
        def makedir(self, newdir):
            """works the way a good mkdir should :)/>
            - already exists, silently complete
            - regular file in the way, raise an exception
            - parent directory(ies) does not exist, make them as well
            """
            
            if os.path.isdir(newdir):
                pass
            elif os.path.isfile(newdir):
                raise OSError("a file with the same name as the desired " \
                          "dir, '%s', already exists." % newdir)
            else:
                head, tail = os.path.split(newdir)
                if head and not os.path.isdir(head):
                    self.makedir(head)
                if tail:
                    os.mkdir(newdir)  
                    
        def info(self,msg):
            print (msg)
            logging.info(msg)
            
        def error(self,msg):
            print ('[ERROR] '+msg)
            logging.error(msg)
            
        def CheckParams(self, params):
            result = False
            if len(params) == 1:
                self.error('Invalid parameters passed')
                print "Parameters:"
                print "    Date (yyyy-mm-dd)"
                result = False
            else:
                result = True
                
            return result           
            
        
        def CallWS(self, param):
            
            result = 1
            try:
                    self.info('Calling Tibco %s WS with parameter: %s' % (WSDESCRIPTOR, param))
                    
                    loc = intfProcess_ESSImporter_serviceLocator()
                    svc = loc.getintfwsProcess_ESSImporterEndpoint1(WEBSERVICEADDRESS)
                    
                    kw = input()
                     
                    kw._FileName = param
                    
                    self.info("Called Tibco with params %(filename)s" % {'filename': param})
                    
                    op = svc.Process_sp_ESSImporter_sp_FeesOp(kw)
                    
                    result = int(op._Result)
                    
                    if result == 0:
                        self.info("Tibco process call was successful")
                    else:
                        self.error("Tibco process call failed with error: %s" % result)
        
            except Exception, e:
                self.error('Error calling the Tibco Web Service: %s: %s' % (e.__class__, e))
                result = 1
                
                
            return result
        
    if __name__ == '__main__':
        
        result = 1    
        tws = TibcoWS(LOGFILE, logging.INFO, 'Starting Web call to %s Tibco service' % WSDESCRIPTOR)
        if tws.CheckParams(sys.argv):
    #        path, filename = os.path.split(FILEPATH % (string.replace(sys.argv[1], '-', '')))
            path = FILEPATH
            filename = FileName
            #print("REMOTEPATH %s filename %s: " % (REMOTEPATH % filename))
            #print("FILEPATH %s filename %s: " % (FILEPATH % filename))
            
            #if getfile(FTPSERVER, FILEPATH % filename, REMOTEPATH % string.replace(sys.argv[1], '-', ''), tws.info, tws.error):
            if getfile(FTPSERVER, FILEPATH, REMOTEPATH % string.replace(sys.argv[1], '-', ''), tws.info, tws.error):
                result = tws.CallWS(FILEPATH % string.replace(sys.argv[1], '-', ''))
                os.remove(FILEPATH % string.replace(sys.argv[1], '-', ''))
                print 'will copy file %s' % filenames
        #time.sleep(600)
        
        tws.info('Exited with code: %s' % result)
        sys.exit(result)
    
    


    The error message is :
    C:\developer\workspace\Python\UnixPowerBroker\Inbound_Dissemination\ESS>python CallTibcoWS.py 2011-11-04
    file exists: C:/ESSSWAP/Archive/Ess_Import/basket_div_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/basket_payment_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/basket_summary_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/basket_swap_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/basket_trade_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/interest_detail_SA.0.20111104
    file exists: C:/ESSSWAP/Archive/Ess_Import/unwind_SA.0.20111104
    Connecting to GenevaServer as geneva with pw C:/Scripts/Python/certs/GENEVA/Priv_Key.ppk
    [ERROR] Error FTPing the file from C:/ESSSWAP/Archive/Ess_Import/ to /export/home/geneva/geneva-4000/extracts/out/20111104: <type 'exceptions.IOError'>: [Errno 2] No such file
  3. In Topic: TypeError: not all arguments converted during string formatting

    Posted 16 Nov 2011

    View Postsepp2k, on 16 November 2011 - 12:46 PM, said:

    "TypeError: not all arguments converted during string formatting" means that you gave more arguments to % than the format string needs. That means that REMOTE_PATH has less than three format specifiers.

    I also notice that in lines 173, 176 and 177 you're calling % with a single argument (sys.argv[1]). While in lines 170 and 175 you give it three arguments. Obviously both can't be correct.


    Looking at line 170 - I am passing two parameters. REMOTEPATH and the dateparameter. On 170, I am simply converting the passed parameter to a string with a different format. If I pass '2011-11-11', that line will change it to 20111111
  4. In Topic: TypeError: not all arguments converted during string formatting

    Posted 16 Nov 2011

    I read somewhere that maybe my passed value is not a string so I tried the below code

    170 - path, filename = os.path.split(REMOTEPATH % int(sys.argv[1]))
    
    


    I just converted the passed value into an int and it is working.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

MastaKay hasn't added any friends yet.

Comments

MastaKay has no profile comments yet. Why not say hello?