Download Files with zagoload

The zagoload allows to access local files and remote files – files which are accessible thought HTTP and FTP protocols – in uniform way.

Version Python github Build Status

Installing zagoload

The zagoload module can be installed by pip:

 # pip install zagoload

You can also clone zagoload github repo.

Basics

To download URL, we will use zagoload.loads(url) which return new FileRequest object.

  • If the file was successfully downloaded, FileRequest.valid will be True.
  • The FileRequest.source will point to the source file
  • The FileRequest.target will point to the downloaded local file on disk. It will downloaded to cache under uniquely generated name
  • The FileRequest.data will contain the contents of the file

In the next example we will download http://www.google.com

sample_01.py
 import zagoload

 def download(source):
   def info(ss):
     import sys ;sys.stdout.write(ss + u'\n')

   ff = zagoload.load(source)

   if ff.valid:
     # if valid, process ff.target - the file on disk
     info( 'Download {0} => {1}'.format(ff.source,ff.target) )
     # or process ff.text - the content of the file
     info( u'{0} characters : {1}'.format(len(ff.text),ff.text[:15].__repr__() ) )
   else:
     info('Failed to download {0}'.format(ff.source))

 download(u'http://www.google.com' )
 download(u'ftp://ftp.funet.fi/pub/standards/RFC/rfc959.txt')
sample_01.py output
 # python sample_01.py
 Download http://www.google.com => Cache/fW/file_fWebvNyPE1OGX2RS.bin
 44994 characters : '<!doctype html>'
 Download ftp://ftp.funet.fi/pub/standards/RFC/rfc959.txt => Cache/sH/file_sHDLNozuH0CkIMUA.bin
 147316 characters : '\n              '