-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_google_image.py
52 lines (42 loc) · 1.34 KB
/
get_google_image.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
import csv
import io
import http.client
import const
read_file_path = '/home/greghovhannisyan/PycharmProjects/289G Project/batch_2.csv'
limit = 25000
counter = 0
def getpng(lat, lon, zoom):
urlpath = (
const.URLBASE +
"?maptype=" + const.MAPTYPE +
"&size=" + const.RESX + "x" + const.RESY +
"¢er=" + str(lat) + "," + str(lon) +
"&zoom=" + str(zoom) +
"&scale=2" +
"&key=" + const.APIKEY
)
conn = http.client.HTTPSConnection(const.HOST)
conn.request("GET", urlpath)
resp = conn.getresponse()
if (resp.status != 200):
print(urlpath)
print(resp.status, resp.reason)
return None
data = resp.read()
return data
def savepng(pngdata, filename):
with io.open(filename, 'wb') as f:
f.write(pngdata)
with open(read_file_path, 'r') as csv_read_file:
my_reader = csv.DictReader(csv_read_file)
for row in my_reader:
if(counter <= limit):
counter +=1
lat = float(row['LATITUDE'])
lon = float(row['LONGITUDE'])
zoom = 19
pngdata = getpng(lat, lon, zoom)
if (pngdata is None):
print("error")
else:
savepng(pngdata, '/home/greghovhannisyan/Desktop/Json_files/google_images_batch_2/' + row['REPORTNUMBER'] + "_google.png")