Skip to content

Commit

Permalink
fetch without faking user agent eny more - use rhtml-no trick. Fix cron.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Insam committed Dec 10, 2010
1 parent 6c170a7 commit 810a696
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/character.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def before_save
end

def armory_url
return "http://#{self.realm.hostname}/character-achievements.xml?r=#{ CGI.escape( self.realm.name ) }&n=#{ CGI.escape( self.name ) }"
return "http://#{self.realm.hostname}/character-achievements.xml?r=#{ CGI.escape( self.realm.name ) }&n=#{ CGI.escape( self.name ) }&rhtml=no"
end

def refresh_from_armory( do_backfill = false )
Expand Down
6 changes: 4 additions & 2 deletions app/models/guild.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'fetcher'

class Guild < ActiveRecord::Base
belongs_to :realm
has_many :characters, :order => "rank"
Expand All @@ -18,7 +20,7 @@ def before_save
end

def armory_url
"http://#{self.realm.hostname}/guild-info.xml?r=#{ CGI.escape( self.realm.name ) }&n=#{ CGI.escape( self.name ) }&p=1"
"http://#{self.realm.hostname}/guild-info.xml?r=#{ CGI.escape( self.realm.name ) }&n=#{ CGI.escape( self.name ) }&p=1&rhtml=no"
end

def refresh_from_armory
Expand All @@ -28,7 +30,7 @@ def refresh_from_armory
begin
xml = Fetcher.fetch(self.armory_url)
rescue Exception => e
STDERR.puts "** Error fetching: #{ e }"
STDERR.puts "** Error fetching: #{ e }\n #{e.backtrace.join("\n ")}"
return
end

Expand Down
4 changes: 2 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W( #{config.root}/lib )

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down Expand Up @@ -46,6 +46,6 @@ class Application < Rails::Application
end

# This is where I monkey patch built-in classes
require "#{Rails.root}/lib/extend_builtins"
#require "#{Rails.root}/lib/extend_builtins"

ARMORY_LANGUAGE = 'en'
4 changes: 3 additions & 1 deletion lib/fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'open-uri'

class Fetcher
def self.fetch( url )
#puts ".. fetching #{url}"
xml = open(url, "User-agent" => 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4', "Accept-Language" => ARMORY_LANGUAGE) do |f|
xml = open(url, "Accept-Language" => ARMORY_LANGUAGE) do |f|
Hpricot.XML(f)
end
return xml
Expand Down

0 comments on commit 810a696

Please sign in to comment.