1 from PIL import Image 2 import MySQLdb 3 import os 4 import urllib 5 import time 6 from multiprocessing.dummy import Pool as ThreadPool 7 8 def gaidu_is_water((latitude,longitude)): 9 while True: 10 try: 11 ll = longitude + ',' + latitude 12 url = "http://api.map.baidu.com/staticimage?center="+ll+"&zoom=18&width=1&height=1" 13 data = urllib.urlretrieve(url, ll) 14 im = Image.open(ll) 15 rgb_im = im.convert('RGB') 16 print rgb_im.getpixel((0, 0)) 17 if rgb_im.getpixel((0, 0)) in [(167, 192, 224),(104, 137, 167),(153, 183, 219)]: 18 # print 'is water' 19 flag = 1 20 else: 21 flag = 0 22 # print 'not water' 23 # print ll,'ok' 24 break 25 except Exception, e: 26 print e 27 time.sleep(5) 28 continue 29 30 if __name__ == '__main__': 31 print gaidu_is_water('114.24419,22.332689') 32 pool = ThreadPool(20) 33 results = pool.map(gaidu_is_water, lls) 34 pool.close() 35 pool.join()