Beispiel #1
0
 def get_image(url, file_dir):
     try:
         data = urllib2.urlopen(url, timeout=gk7.HTTP_TIME_OUT).read()
         # 文件路径
         file_path = '%s/%s' % (file_dir, url[url.rfind('/') + 1:])
         with open(file_path, 'w') as f_data:
             f_data.write(data)
         # 压缩
         ImageUtil.compress(file_path, gk7.PIC_MAX_WIDTH)
     except Exception as e:
         ## 延迟20s后重试
         DownloadTask.get_image.retry(countdown=20, exc=e)
     return file_path
Beispiel #2
0
 def get_image(url, file_dir):
     try:
         data = urllib2.urlopen(url, timeout=gk7.HTTP_TIME_OUT).read()
         # 文件路径
         file_path = '%s/%s' %(file_dir, url[url.rfind('/')+1:])
         with open(file_path, 'w') as f_data:
             f_data.write(data)
         # 压缩
         ImageUtil.compress(file_path, gk7.PIC_MAX_WIDTH)
     except Exception as e:
         ## 延迟20s后重试
         DownloadTask.get_image.retry(countdown=20, exc=e)
     return file_path
Beispiel #3
0
 def get_image(url, file_dir):
     try:
         data = urllib2.urlopen(url).read()
         # 文件路径
         file_path = '%s/%s' %(file_dir, url[url.rfind('/')+1:])
         with open(file_path, 'w') as f_data:
             f_data.write(data)
         # 压缩
         ImageUtil.compress(file_path, gk7.PIC_MAX_WIDTH)
     except Exception as e:
         logger.error(u'下载文件失败,url:%s,文件目录:%s,原因:%s' %(url, file_dir, str(e)))
         ## 延迟20s后重试
         DownloadTask.get_image.retry(countdown=20, exc=e)
     return file_path