示例#1
0
文件: web.py 项目: kiote/cosmopolitan
 def _already_downloaded(self):
     try:
         open(self.file_name)
         return True
     except FileNotFoundError as e:
         sos._super_log('Downloading the file...')
         return False
示例#2
0
 def _already_downloaded(self):
     try:
         open(self.file_name)
         return True
     except FileNotFoundError as e:
         sos._super_log('Downloading the file...')
         return False
示例#3
0
文件: web.py 项目: kiote/cosmopolitan
    def _retreive(self):
        try:
            res = request.urlretrieve(self.url, self.file_name)
        except Exception as e:
            sos._super_log("Was about to retreive %s, but got error: %s"
                           % (self.url, str(e)))
            return None

        return res
示例#4
0
    def _retreive(self):
        try:
            res = requests.get(self.url, steam=True)
            with open(self.file_name, 'wb') as fd:
                for chunk in r.iter_content(chunk_size):
                    fd.write(chunk)
        except Exception as e:
            sos._super_log("Was about to retreive %s, but got error: %s"
                           % (self.url, str(e)))
            return None

        return res
示例#5
0
    def _retreive(self):
        try:
            res = requests.get(self.url, stream=True)
            with open(self.file_name, 'wb') as fd:
                for chunk in res.iter_content(1024 * 64):
                    fd.write(chunk)
        except Exception as e:
            sos._super_log("Was about to retreive %s, but got error: %s"
                           % (self.url, str(e)))
            return None

        return res
示例#6
0
def prepare_data(file_data={}):
    file_name = FOLDER + file_data["file_name"]

    sweb.Webfile(url=HOST + HTTP_PATH + file_data["file_name"],
                 file_name=file_name).download()

    if not os.path.exists(file_name):
        sos._super_log("Can't proceed, file %s not found" % file_name)
        return 1

    # unzip zip file
    outpath = FOLDER + file_data["file_name_without_extension"] + "/"
    sos.Unzip(file_name=file_name, outpath=outpath).run()

    # call org2org on unzipped stuff
    sos._format_ogr2ogr(path=FOLDER + file_data["file_name_without_extension"],
                        file_name=file_data["file_name_without_extension"])
    # handle *.Polygon file
    file_full_path = FOLDER + file_data["file_name_without_extension"]
    return sos.LoadPolygon(file_full_path).run()