initial commit
This commit is contained in:
commit
d723f35a71
1 changed files with 57 additions and 0 deletions
57
streetview.py
Normal file
57
streetview.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import urllib2
|
||||||
|
from xml.etree.ElementTree import ElementTree, fromstring
|
||||||
|
from PIL import Image
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
exit("need to supply lat, lon and zoom (0-5)")
|
||||||
|
|
||||||
|
lat = sys.argv[1]
|
||||||
|
lon = sys.argv[2]
|
||||||
|
zoom = int(sys.argv[3])
|
||||||
|
|
||||||
|
# yaw north: 0 south: 180 east: 90 west: 270
|
||||||
|
# pitch up: -90 down: 90
|
||||||
|
# http://cbk0.google.com/cbk?output=xml&panoid=p-DIQUVaFuGHWxVqpLstbA
|
||||||
|
|
||||||
|
try:
|
||||||
|
xml = urllib2.urlopen("http://cbk0.google.com/cbk?output=xml&ll=%s,%s"%(lat, lon))
|
||||||
|
except urllib2.HTTPError as e:
|
||||||
|
exit(e.code + " " + e.msg)
|
||||||
|
|
||||||
|
doc = fromstring(xml.read())
|
||||||
|
pano_id = doc.find("data_properties")
|
||||||
|
|
||||||
|
if pano_id is None:
|
||||||
|
exit("no streetview data avaiable here")
|
||||||
|
|
||||||
|
pano_id = pano_id.get("pano_id")
|
||||||
|
|
||||||
|
gridsizes = [(1, 1),
|
||||||
|
(2, 1),
|
||||||
|
(4, 2),
|
||||||
|
(6, 3),
|
||||||
|
(13, 7),
|
||||||
|
(26, 13)]
|
||||||
|
|
||||||
|
panorama = Image.new("RGB", (gridsizes[zoom][0]*512, gridsizes[zoom][1]*512))
|
||||||
|
|
||||||
|
try:
|
||||||
|
for x in xrange(gridsizes[zoom][0]):
|
||||||
|
for y in xrange(gridsizes[zoom][1]):
|
||||||
|
tile = urllib2.urlopen("http://cbk0.google.com/cbk?output=tile&panoid=%s&zoom=%d&x=%d&y=%d"%(pano_id, zoom, x, y))
|
||||||
|
imtile = Image.open(StringIO(tile.read()))
|
||||||
|
panorama.paste(imtile, (x*512, y*512))
|
||||||
|
except urllib2.HTTPError as e:
|
||||||
|
exit(e.code + " " + e.msg)
|
||||||
|
|
||||||
|
panorama.save("panorama.jpg")
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = urllib2.urlopen("http://cbk0.google.com/cbk?output=thumbnail&w=416&h=208&ll=%s,%s"%(lat, lon))
|
||||||
|
open("thumbnail.jpg", "w").write(url.read())
|
||||||
|
except urllib2.HTTPError as e:
|
||||||
|
exit(e.code + " " + e.msg)
|
Loading…
Reference in a new issue