Skip to content

Instantly share code, notes, and snippets.

@tamalw
Created March 10, 2011 20:27
Show Gist options
  • Save tamalw/864862 to your computer and use it in GitHub Desktop.
Save tamalw/864862 to your computer and use it in GitHub Desktop.
Loads GE prices into Soulver's variables
require 'rubygems'
require 'open-uri'
require 'plist'
require 'hpricot'
variables_path = "#{ENV['HOME']}/Library/Application Support/Soulver/Variables.plist"
items = {
1391 => "Battlestaff",
573 => "Air orb",
575 => "Earth orb",
569 => "Fire orb",
571 => "Water orb",
561 => "Nature rune"
}
# Don't need to touch anything below
module GE
class Item
attr_reader :obj
def initialize(obj)
@obj = obj
end
def name
doc.at(".main_ge_page .subsectionHeader").inner_text.strip
end
def examine
additional[/^.*\.$/]
end
def current_price
raw = additional[/^Current guide price: (.*)$/, 1].strip.delete(',')
case raw[-1]
when 'b'
(raw.to_f * 1_000_000_000).to_i
when 'm'
(raw.to_f * 1_000_000).to_i
when 'k'
(raw.to_f * 1_000).to_i
else
raw.to_i
end
end
def day_change_30
additional[/^30 Days: (.*)$/, 1]
end
def day_change_90
additional[/^90 Days: (.*)$/, 1]
end
def day_change_180
additional[/^180 Days: (.*)$/, 1]
end
private
def doc
@doc ||= Hpricot(open("http://itemdb-rs.runescape.com/viewitem.ws?obj=#{obj}"))
end
def additional
@additional ||= doc.at("#item_additional").inner_text.strip
end
end
end
variables = Plist::parse_xml(variables_path)
items.each do |item_id, item_name|
puts "Updating #{item_name}"
ge_data = GE::Item.new(item_id)
name = "GE" << ge_data.name.downcase.gsub(' ', '_').gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
variables['SKVariables'].delete_if { |v| v['name'] == name }
variables['SKVariables'] << {
"name" => name,
"enabled" => true,
"value" => ge_data.current_price.to_s,
"type" => 0
}
end
File.rename(variables_path, "#{ENV['HOME']}/Library/Application Support/Soulver/Variables.#{Time.now.to_i}.plist")
File.open(variables_path, "w") do |f|
f.puts variables.to_plist
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment