Created
January 3, 2009 14:35
-
-
Save JamesHarrison/42880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'RMagick' | |
# Retrieves a corporation logo for a corporation | |
class GetCorporationLogoJob < Struct.new(:corporation_id) | |
def perform | |
File.open("#{RAILS_ROOT}/public/system/corporations/#{corporation_id.to_i}_64.png","wb") do |f| | |
Net::HTTP.start("clg.eve-metrics.com") do |http| | |
resp = http.get("/#{corporation_id.to_i.to_s}.png") | |
return unless resp | |
if resp.response['Location'] then | |
unless resp.response['Location'].include?"not_in_alliance.png" | |
url = URI.parse(resp.response['Location']) | |
res2 = Net::HTTP.start(url.host, url.port) {|http2| | |
f << http2.get(url.path).body | |
} | |
end | |
end | |
end | |
end | |
# Now use RMagick to bake some 16/32 images. | |
img = Magick::Image::read("#{RAILS_ROOT}/public/system/corporations/#{corporation_id.to_i}_64.png")[0] | |
if File.exists?("#{RAILS_ROOT}/public/system/corporations/#{corporation_id.to_i}_64.png") and img != nil | |
img.scale(32,32).write("#{RAILS_ROOT}/public/system/corporations/#{corporation_id.to_i}_32.png") | |
img.scale(16,16).write("#{RAILS_ROOT}/public/system/corporations/#{corporation_id.to_i}_16.png") | |
c = Corporation.find(corporation_id) # Mark as having got logo successfully | |
c.logo_fetched_at = Time.now | |
c.got_logo = true | |
c.save | |
else | |
c = Corporation.find(corporation_id) # Mark as having failed; will retry in a few days | |
c.logo_fetched_at = Time.now | |
c.save | |
end | |
end | |
def errors | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment