Skip to content

Instantly share code, notes, and snippets.

@AumCoin
Created September 9, 2016 21:49
Show Gist options
  • Save AumCoin/1f32b9826c03402a58bae7cef650be06 to your computer and use it in GitHub Desktop.
Save AumCoin/1f32b9826c03402a58bae7cef650be06 to your computer and use it in GitHub Desktop.
def rip_prices ### This takes about 3 minutes
products = {}
currencies = ["EUR","USD"]#,"GBP","AUD","CAD","CZK","DKK","MXN","NOK","SEK","TRY"]
currencies.each do |currency|
unless File.exist?("google_" + currency + "_english_1.xml")
puts "File google_" + currency + "_english_1.xml does not exist. Skipping..."
next
end
puts "processing " + currency + " file."
doc = XmlSimple.xml_in (File.open("google_" + currency + "_english_1.xml", "r").read); nil
i = 0
doc["channel"][0]["item"].each do |item|
itemno = item["id"][0]
price = item["price"][0].split[0]
products[itemno] ||= {}
products[itemno]["prices"] = {}
products[itemno]["prices"][currency] = price
i += 1
end
end
puts products
Dir.chdir "C:\\MyScripts\\DB\\Data"
YAML.dump(products, File.open("kinguin_prices_hash.yml", 'w'))
sleep 1
end
RAW Paste Data
AdClubhouse: Project management software you'll actually enjoy using.
def rip_prices ### This takes about 3 minutes
products = {}
currencies = ["EUR","USD"]#,"GBP","AUD","CAD","CZK","DKK","MXN","NOK","SEK","TRY"]
currencies.each do |currency|
unless File.exist?("google_" + currency + "_english_1.xml")
puts "File google_" + currency + "_english_1.xml does not exist. Skipping..."
next
end
puts "processing " + currency + " file."
doc = XmlSimple.xml_in (File.open("google_" + currency + "_english_1.xml", "r").read); nil
i = 0
doc["channel"][0]["item"].each do |item|
itemno = item["id"][0]
price = item["price"][0].split[0]
products[itemno] ||= {}
products[itemno]["prices"] = {}
products[itemno]["prices"][currency] = price
i += 1
end
end
puts products
Dir.chdir "C:\\MyScripts\\DB\\Data"
YAML.dump(products, File.open("kinguin_prices_hash.yml", 'w'))
sleep 1
end
@baweaver
Copy link

baweaver commented Sep 9, 2016

def rip_prices   ### This takes about 3 minutes
  products = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
  currencies = ["EUR","USD"]#,"GBP","AUD","CAD","CZK","DKK","MXN","NOK","SEK","TRY"]

  currencies.each do |currency|
    unless File.exist?("google_" + currency + "_english_1.xml")
      puts "File google_" + currency + "_english_1.xml does not exist.  Skipping..."
      next
    end

    puts "processing " + currency + " file."

    doc_file = File.open("google_" + currency + "_english_1.xml", "r").read
    doc      = XmlSimple.xml_in(doc_file); nil

    doc["channel"][0]["item"].each do |item|
      itemno = item["id"][0]
      price  = item["price"][0].split[0]

      products[itemno]["prices"][currency] = price
    end
  end

  p products

  Dir.chdir "C:\\MyScripts\\DB\\Data"
  YAML.dump(products, File.open("kinguin_prices_hash.yml", 'w'))

  sleep 1
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment