@ -8,6 +8,18 @@ $panoramios = Hash.new
namespace :migrate do
namespace :migrate do
desc " Migrates data from live site to current database "
desc " Migrates data from live site to current database "
task test : :environment do
#url = 'http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=20&minx=-180&miny=-90&maxx=180&maxy=90&size=medium&mapfilter=true'
#response = RestClient.get url
result = Geocoder . search ( 'Calgary Alberta, Canada' ) . first
#begin
points = Geocoder :: Calculations . bounding_box ( [ result . latitude , result . longitude ] , 5 , { :unit = > :km } )
options = { :set = > :public , :size = > :original , :from = > 0 , :to = > 20 , :mapfilter = > false , :miny = > points [ 0 ] , :minx = > points [ 1 ] , :maxy = > points [ 2 ] , :maxx = > points [ 3 ] }
url = 'http://www.panoramio.com/map/get_panoramas.php?' + options . to_query
response = JSON . parse ( open ( url ) . read )
puts response [ 'photos' ]
end
task all : :environment do
task all : :environment do
migrate! User . new
migrate! User . new
migrate! Location . new
migrate! Location . new
@ -258,13 +270,15 @@ namespace :migrate do
$panoramios [ location ] || = 0
$panoramios [ location ] || = 0
$panoramios [ location ] += 1
$panoramios [ location ] += 1
result = Geocoder . search ( location ) . first
result = Geocoder . search ( location ) . first
begin
# begin
if result
if result
points = Geocoder :: Calculations . bounding_box ( [ result . latitude , result . longitude ] , 5 , { :unit = > :km } )
points = Geocoder :: Calculations . bounding_box ( [ result . latitude , result . longitude ] , 5 , { :unit = > :km } )
response = RestClient . get 'http://www.panoramio.com/map/get_panoramas.php' , :params = > { :set = > :public , :size = > :original , :from = > 0 , :to = > 20 , :mapfilter = > false , :miny = > points [ 0 ] , :minx = > points [ 1 ] , :maxy = > points [ 2 ] , :maxx = > points [ 3 ] }
options = { :set = > :public , :size = > :original , :from = > 0 , :to = > 20 , :mapfilter = > false , :miny = > points [ 0 ] , :minx = > points [ 1 ] , :maxy = > points [ 2 ] , :maxx = > points [ 3 ] }
if response . code == 200
url = 'http://www.panoramio.com/map/get_panoramas.php?' + options . to_query
response = JSON . parse ( open ( url ) . read )
#if response.code == 200
i = 0
i = 0
JSON . parse ( response . to_str ) [ 'photos' ] . each { | img |
response [ 'photos' ] . each { | img |
if img [ 'width' ] . to_i > 980
if img [ 'width' ] . to_i > 980
i += 1
i += 1
if i > = $panoramios [ location ]
if i > = $panoramios [ location ]
@ -278,9 +292,9 @@ namespace :migrate do
end
end
end
end
}
}
#end
end
end
end
#rescue; end
rescue ; end
return params
return params
end
end