@ -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,29 +270,31 @@ 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 } )
resp onse = Res tCl ient . get 'http://www.panoramio.com/map/get_panoramas.php' , :param s = > { :set = > :public , :size = > :original , :from = > 0 , :to = > 20 , :mapfilter = > false , :miny = > points [ 0 ] , :minx = > points [ 1 ] , :maxy = > points [ 2 ] , :maxx = > points [ 3 ] }
op tion s = { :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
i = 0
response = JSON . parse ( open ( url ) . read )
JSON . parse ( response . to_str ) [ 'photos' ] . each { | img |
#if response.code == 200
if img [ 'width' ] . to_i > 98 0
i = 0
i += 1
response [ 'photos' ] . each { | img |
if i > = $panoramios [ location ]
if img [ 'width' ] . to_i > 980
params [ " remote_ #{ column . to_s } _url " . to_sym ] = img [ 'photo_file_url' ]
i += 1
params [ column . to_sym ] = img [ 'photo_file_url' ] . gsub ( / ^.* \/ (.*)$ / , '\1' )
if i > = $panoramios [ location ]
params [ :cover_attribution_id ] = img [ 'photo_id ' ]
params [ " remote_ #{ column . to_s } _url " . to_sym ] = img [ 'photo_file_url ' ]
params [ :cover_attribution_user_id ] = img [ 'owner_id' ]
params [ column . to_sym ] = img [ 'photo_file_url' ] . gsub ( / ^.* \/ (.*)$ / , '\1' )
params [ :cover_attribution_name ] = img [ 'owner_name ' ]
params [ :cover_attribution_id ] = img [ 'photo_id ' ]
params [ :cover_attribution_src ] = 'panoramio'
params [ :cover_attribution_user_id ] = img [ 'owner_id' ]
return params
params [ :cover_attribution_name ] = img [ 'owner_name' ]
end
params [ :cover_attribution_src ] = 'panoramio'
end
return params
}
end
end
end
end
}
rescue ; end
#end
end
#rescue; end
return params
return params
end
end