Advertisement
Guest User

Looty Forum Post Generator

a guest
Sep 4th, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.30 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'pp'
  4. require 'csv'
  5.  
  6. league = "Beyond"
  7.  
  8. puts "BB begins here"
  9. puts "--------------"
  10.  
  11. puts "IGN is Koverina, PM me in game if you want to make a purchase"
  12.  
  13. # This creates an array of arrays - but we only need the first field
  14. data = CSV.read(ARGV[0]).map! {|line| line.first}
  15.  
  16. # Only use buyout tabs - temporary workaround until Looty does specific tab export
  17. data = data.reject! {|line| line !~ /^~b\/o/}.compact
  18.  
  19. # Parse for buyouts, line is a string like "~b/o 2 chaos x:1 y:2"
  20. prices = {}
  21. items  = []
  22. data.each do |line|
  23.   buyout = line.match(/^(.*)\s\bx:/)[1]
  24.   x      = line.match(/\bx:(\d*)\b/)[1]
  25.   y      = line.match(/\by:(\d*)\b/)[1]
  26.   prices[buyout] = [] if prices[buyout].nil?
  27.   # Looty indexs coords from 1, PoE indexes from 0
  28.   prices[buyout] << { :x => x.to_i - 1, :y => y.to_i - 1 }
  29. end
  30.  
  31. # Needed until Looty can give us the stash ID in the CSV
  32. stash_offset = 7
  33. stashes = prices.keys
  34.  
  35. # Now re-loop to produce the bbcode
  36. prices.each do |price,items|
  37.   puts ""
  38.   puts "[spoiler=\"#{price}\"]"
  39.   items.each do |item|
  40.     location = "Stash#{stashes.index(price)+stash_offset}"
  41.     coord    = "x=\"#{item[:x]}\" y=\"#{item[:y]}\""
  42.     print "[linkItem location=\"#{location}\" league=\"#{league}\" #{coord}]"
  43.   end
  44.   puts ""
  45.   puts "[/spoiler]"
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement