Pages

Wednesday, August 17, 2016

How to Download content from WCC server using Python ?


How to Download content from WCC server using Python ?

How to download content from web site using Python ?


Source code : 


Main Tasks


1. Getting login URL and parameters

2. Getting contentID and Original file name by 

calling DOC_INFO

3. Run GET_FILE service and redirect output to 

file




WCC server ->ucm.company.com:16200

1


2. Getting contentID and Original file name by calling DOC_INFO






Code Snipet :
docinfo_data = urllib.urlencode({
'dID' : dID,
'idcToken' : idctoken,
'IdcService' : 'DOC_INFO',
'IsSoap' : '1'
})
print ('Getting Doc info ' + dID)
start_time = timeit.default_timer()
resp = opener.open('http://'+UCMIP+':'+UCMPORT+'/cs/idcplg?',docinfo_data)
regex ='dOriginalName="*"'
c = 0
pattern = re.compile(regex)
for line in resp:
if re.findall(pattern,line):
tempwor = line.split('="')
for wor in line.split('="'):
if ( re.search('dDocName',wor)):
dDocName = (tempwor[c+1].split('"')[0])
elif ( re.search('dOriginalName',wor)):
dOriginalName = (tempwor[c+1].split('"')[0])


a.dID is passed with DOC_INFO service

b.regex ='dOriginalName="*"' is used for original file


matching

c.After getting output , it is split by '=”'

d. Then get the dDocName & original file




3. Run GET_FILE service and redirect output to file
:
download_data = urllib.urlencode({
'dID' : dID,
'dDocName' : dDocName ,
'allowInterrupt' : '1' ,
'IdcService' : 'GET_FILE' ,
'idcToken' : idctoken
})
start_time = timeit.default_timer()
resp = opener.open('http://'+UCMIP+':'+UCMPORT+'/cs/idcplg?',download_data)
file.write(resp.read())
file.close()



a.GET_FILE service is called by passing dID,dDocName
b. New file will be created with name of original file .
Output : Correct dID
    ./downloadbydID 3928


Loging to ucm.company.com:16201
Time Taken : 3.0563950538635254
Getting Doc info 3928
Time Taken : 1.2068860530853271
Downloadig dDocName: STJACOBO003527 ,FileName: simple.pdf
simple.pdf is created
Time Taken : 16.195816040039062


    ./downloadbydID 3999
Loging to ucm.company.com:16201
Time Taken : 3.349163055419922
Getting Doc info 3999
Time Taken : 0.9225029945373535
wrong dID .. exiting



Source code : 

No comments:

Post a Comment