-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
52 lines (42 loc) · 1.39 KB
/
test.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
#!/usr/local/bin/python
# test.py - test MySQL access and all
import MySQLdb
import MySQLdb.cursors
import sys
import urllib
import datetime
import hashlib
try:
conn = MySQLdb.connect (host = "localhost",
user = "root",
passwd = "xxxxxxxxxx",
db = "traffic_cam")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit (1)
cursor1 = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor2 = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor1.execute ("SELECT * FROM webcam")
cursor2.execute ("SELECT * FROM webcamimage ")
result_set = cursor1.fetchall()
img=cursor2.fetchall()
for a in result_set:
url = a["URL"]
name = a["name"]
check_size = urllib.urlopen(url)
meta = check_size.info()
image_size=meta.getheaders("Content-Length")[0]
time_now = datetime.datetime.now()
toMD5 = name + str(image_size) + str(time_now)
blob = hashlib.md5(toMD5).hexdigest()
print "%s -> %s -> %s" % (name, image_size, blob)
# cursor.execute ("""
# INSERT INTO webcamimage (`blob`, `webcam`, `timestamp`, `size`)
# VALUES (%s, %s, %s, %s)
# """, (blob, name, time_now, image_size))
# write image on disk
# urllib.urlretrieve(url, name)
#conn.commit()
cursor1.close()
cursor2.close()
conn.close()