From Media Design: Networked & Lens-Based wiki
Jump to navigation Jump to search

This script retrieves the geographic coordinates of a url and retrieves the closest geolocated picture available on panoramio. You need to get PygeoIP to be able to use it.

import pygeoip
import os
import urllib, urlparse 
import json

#what database?
gi = pygeoip.GeoIP('pathtodatabase/GeoLiteCity.dat')
#url input
url = raw_input("Where shall we go now? ")

#recuperation complete des donnees
infos = gi.record_by_name(url)

#on garde les coordonnees
Latitude = infos.get('latitude')
Longitude = infos.get('longitude')

print Longitude
print Latitude

add = 0.002

def someFunction(add):

	#etablir le perimetre
	LatitudeMin = Latitude - add
	LatitudeMax = Latitude + add
	LongitudeMin = Longitude - add
	LongitudeMax = Longitude + add

	#transformation chaine caracteres
	LatitudeMin = str(LatitudeMin)
	LatitudeMax = str(LatitudeMax)
	LongitudeMin = str(LongitudeMin)
	LongitudeMax = str(LongitudeMax)

	# query for images
	url = ''+ LongitudeMin +'&miny='+ LatitudeMin +'&maxx='+ LongitudeMax +'&maxy='+ LatitudeMax +'&size=original'

	print url
	c = urllib.urlopen(url)

	# get the urls of individual images from JSON
	j = json.loads( 
	imurls = []
	for im in j['photos']:

	# download images
	for url in imurls:
	    image = urllib.URLopener()
	    image = urlparse.urlparse(url).path
	    print 'downloading:', url

	if len(imurls) ==0: