-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL_DIS.py
81 lines (67 loc) · 1.87 KB
/
L_DIS.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
75
76
77
78
79
80
81
#!/bin/usr/python
# encoding: utf-8
import os # mkdir
import time
import sys # path
import shutil # rmtree
import cx_Oracle
import imghdr
import urllib
import urllib2
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
# url save images
def downloadimage(args):
pass
#
def geturl(args):
pass
def mkimages():
if os.path.exists('images'):
shutil.rmtree('images')
print "rm images"
time.sleep(1)
os.mkdir('images')
print "mkdir images"
else:
os.mkdir('images')
print "mkdir images"
#
def start():
mkimages()
cp_in = open('hphm.txt')
lines = cp_in.readlines()
print lines
try:
db = cx_Oracle.connect('si01', 'jp2011', '100.11.44.237/SICSDB')
for line in lines:
cphm = line[3:9]
# print cphm
path = 'images/%s' % cphm
# path = unicode(path,"GB2312")# chinese code problem
os.mkdir(path)
for i in range(0, 10):
cursor = db.cursor()
sql = 'select * from car_tab_temp where HPHM = \'鄂%s\'' % cphm
# print sql
cursor.execute(sql)
results = cursor.fetchall()
try:
url = results[i][11]
print url
except Exception as e:
break
try:
response = urllib2.urlopen(url, timeout=1)
webpage = response.read()
print imghdr.what('', webpage)
print 'ok'
urllib.urlretrieve(url, u'%s/%d.jpg' % (path, i))
print "image saved"
except Exception as e:
print 'timeout'
except Exception as e:
print 'Some worry happend', e
finally:
db.close()
cp_in.close()
start()