-
Notifications
You must be signed in to change notification settings - Fork 28
/
down_pic.py
74 lines (62 loc) · 1.91 KB
/
down_pic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
读取文件,下载图片
author: zihao.chen
date: 2017/6/28
descrption: 此模块详细作用描述
"""
# import xlrd
# import urllib
import os
# import datetime
# import urllib2
import shutil
# import urllib
# import numpy as np
from utils.utils_ import touch_dir
class DownloadPic(object):
def __init__(self):
self.document_path=''
self.save_path = '/home/yuexibin/bddog/imgdata/test1'
self.table_name = ''
self.start_index = 0
self.root_path = os.getcwd()
def down_save_pic(self,task):
print task
pic_url = task[1]
raw_image_path = os.path.join(self.save_path,pic_url+'.jpg')
img_save_path = task[0]
try:
print raw_image_path,img_save_path
shutil.copy(raw_image_path,img_save_path)
except Exception as e:
print 'error'
print e.message
def load_urls(self):
root_dir = '/home/yuexibin/bddog/imgdata/all_img'
dog_keys = {}
down_tasks = []
inf = open('test.txt','rb')
lines = inf.readlines() # 读取全部内容
for line in lines:
line = line.strip('\r\n')
key_value = line.split(' ')
print key_value
if not dog_keys.has_key(key_value[1]):
dog_keys[key_value[1]]=100
save_dir = key_value[1]
save_dir = os.path.join(root_dir,save_dir)
touch_dir(save_dir)
save_path = os.path.join(save_dir,str(dog_keys[key_value[1]])+'.jpg')
task = [save_path,key_value[0]]
dog_keys[key_value[1]] +=1
down_tasks.append(task)
return down_tasks
def main(self):
tasks = self.load_urls()
print '待下载任务数:',len(tasks)
for i in range(len(tasks)):
self.down_save_pic(tasks[i])
dp = DownloadPic()
dp.main()