satelliteData.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:Tethys 作者: JosePedroMatos 项目源码 文件源码
def _downloadFile(self, toDownload):
        '''
        Downloads the file from the url and saves it in the directory folderPath with the name fileName.
        '''
        fileName, url = toDownload

        # Opens the web page and creates a file in the folder folderPAth and with the name fileName
        try:
#===============================================================================
#             passman = request.HTTPPasswordMgrWithDefaultRealm()
#             passman.add_password(self.realm, url, self.username, self.password)
# 
#             authhandler = request.HTTPBasicAuthHandler(passman)
#             opener = request.build_opener(authhandler)
#             request.install_opener(opener)
#===============================================================================
            u = request.urlopen(url)

            f = open(fileName, 'wb')

            block_sz = 8192
            while True:
                buffer = u.read(block_sz)
                if not buffer:
                    break

                f.write(buffer)

            # Closes the file
            f.close()
            u.close()

            return os.path.getsize(fileName)

        except Exception as ex:
            warnings.warn(str(ex), UserWarning)

            return -1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号