예제 #1
0
    def download_spectra(self, dir, files):
        self.my_dir = Dir(os.path.join(dir,self.name))
        self.my_dir.remove() # delete temp dir for download with old files
        self.my_dir.create() # create new one
        self.download_names = []

        for url in files:
            file_name = url.split('/').pop() #last part
            file_name = file_name.split('?')[0] # just *.fits
            download_name = os.path.join(dir, self.name)
            download_name = os.path.join(download_name, file_name)

#            print url
            try:
                    s = urllib2.urlopen(url)
                    content = s.read()
                    s.close()
                    d = open(download_name,'w')
                    d.write(content)
                    d.close()
                    self.download_names.append(download_name)

            except IOError:
                print "Could not download file %s!" % url
                pass
예제 #2
0
 def download(self, url):
     try:
         s = urllib2.urlopen(url)
         content = s.read()
         s.close()
         d = open(self.name,'w')
         d.write(content)
         d.close()
     except IOError:
         print "Could not download file"