This commit is contained in:
momoko saunders
2014-07-18 18:56:35 -07:00
168 changed files with 6133 additions and 966 deletions
+37 -18
View File
@@ -8,6 +8,18 @@ $panoramios = Hash.new
namespace :migrate do
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
migrate! User.new
migrate! Location.new
@@ -119,7 +131,7 @@ namespace :migrate do
{
:id => id,
:name => object[:title],
:slug => object[:path].gsub(/^.*\/(.*)$/, '\1'),
:slug => object[:path].gsub(/^.*\/(.*)$/, '\1').gsub(/[\.\#\?\!]/, ''),
:email_address => object[:email] && object[:email].first ? object[:email]['und'][0]['url'] : nil,
:url => object[:field_website] && object[:field_website].first ? object[:field_website]['und'][0]['url'] : nil,
:year_founded => object[:field_year_founded] && object[:field_year_founded].first ? object[:field_year_founded]['und'][0]['value'] : nil,
@@ -188,12 +200,14 @@ namespace :migrate do
end
def conference_post_save(json, object)
object.locations << location
i = 0
#puts "\nORGS:\t" + json[:field_host_organizations].to_json.to_s
json[:field_host_organizations]['und'].each { |u|
#puts "\nORG:\t" + u.to_json
object.conference_host_organizations << ConferenceHostOrganization.new(:organization_id => u['target_id'].to_i, :order => i)
i += 1
}
#puts object.to_json.to_s
object.save!
end
@@ -256,26 +270,31 @@ namespace :migrate do
$panoramios[location] ||= 0
$panoramios[location] += 1
result = Geocoder.search(location).first
#begin
if result
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]}
if response.code == 200
i = 0
JSON.parse(response.to_str)['photos'].each { |img|
if img['width'].to_i > 980
i += 1
if i >= $panoramios[location]
params["remote_#{column.to_s}_url".to_sym] = img['photo_file_url']
params[column.to_sym] = img['photo_file_url'].gsub(/^.*\/(.*)$/, '\1')
params[:cover_attribution_id] = img['owner_id']
params[:cover_attribution_name] = img['owner_name']
params[:cover_attribution_src] = 'panoramio'
return params
end
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)
#if response.code == 200
i = 0
response['photos'].each { |img|
if img['width'].to_i > 980
i += 1
if i >= $panoramios[location]
params["remote_#{column.to_s}_url".to_sym] = img['photo_file_url']
params[column.to_sym] = img['photo_file_url'].gsub(/^.*\/(.*)$/, '\1')
params[:cover_attribution_id] = img['photo_id']
params[:cover_attribution_user_id] = img['owner_id']
params[:cover_attribution_name] = img['owner_name']
params[:cover_attribution_src] = 'panoramio'
return params
end
}
end
end
}
#end
end
#rescue; end
return params
end
+22
View File
@@ -0,0 +1,22 @@
namespace :regenerate do
desc "Regenerates images"
task conference_posters: :environment do
Conference.all.each { |m|
m.poster.recreate_versions!
}
end
task organization_avatars: :environment do
Organization.all.each {|m| m.avatar.recreate_versions!}
end
task conference_covers: :environment do
Conference.all.each {|m| m.cover.recreate_versions!}
end
task organization_covers: :environment do
Organization.all.each {|m| m.cover.recreate_versions!}
#puts Rails.configuration.database_configuration[Rails.env].to_json.to_s
end
end