Download Files with zagoload - part 3

Download to target

If target is emitted, the file will be downloaded to cache under uniquely generated name. If target parameter is provided :

  • If the file start with @, the file will download to following path after it
  • if the file is without extension will be to downloaded to cache under {target}_{id}.bin
  • if the file is with extension will be to downloaded to cache under {target}_{id}.{extension}
sample_03.py
 import zagoload
 def download(source,target):
   def info(ss):
     import sys ;sys.stdout.write(ss + u'\n')
   ff = zagoload.load(source,target=target)
   if ff.valid:
     info(u'{0} => {1}'.format(ff.source,ff.target))
   else:
     info('Failed to download {0}'.format(ff.source))
 download( 'http://www.google.com', '01.txt' )
 download( 'http://www.google.com', '01' )
 download( 'http://www.google.com', '@01.txt' )
sample_03.py output
 # python sample_03.py
 http://www.google.com => Cache/fW/01_fWebvNyPE1OGX2RS.txt
 http://www.google.com => Cache/fW/01_fWebvNyPE1OGX2RS.bin
 http://www.google.com => 01.txt