Last active
July 30, 2020 19:21
-
-
Save Supermathie/da853cb54b991ad2a4901edb1a5fb59a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
# Proof of concept by Michael Brown (@supermathie) | |
require 'colorize' | |
require 'json' | |
require 'net/http' | |
REALM = ENV.fetch('POE_REALM', 'pc') | |
LEAGUE = ENV.fetch('POE_LEAGUE', 'Harvest') | |
TABNAME = ENV.fetch('POE_TABNAME', 'Benches') | |
ACCOUNTNAME = ENV.fetch('POE_ACCOUNTNAME') | |
POESESSID = ENV.fetch('POE_SESSIONID') | |
COLOURINGS = [ | |
[ 'Red', 'red' ], | |
[ 'Green', 'green' ], | |
[ 'Blue', 'blue' ], | |
[ 'White', 'white' ], | |
[ 'Attack', 'light_red' ], | |
[ 'Caster', 'light_blue' ], | |
[ 'Chaos', 'green' ], | |
[ 'Cold', 'cyan' ], | |
[ 'Critical', 'light_blue' ], | |
[ 'Defence', 'magenta' ], | |
[ 'Fire', 'light_red' ], | |
[ 'Influence', 'yellow' ], | |
[ 'Life', 'light_magenta' ], | |
[ 'Lightning', 'yellow' ], | |
[ 'Physical', 'red' ], | |
[ 'Speed', 'green' ], | |
[ 'Augment', 'on_green' ], | |
[ 'Fracture', 'on_blue' ], | |
[ 'Remove', 'on_red' ], | |
[ 'Reroll', 'on_yellow' ], | |
] | |
def getTabs | |
uri = URI.parse("https://www.pathofexile.com/character-window/get-stash-items?accountName=#{ACCOUNTNAME}&realm=#{REALM}&league=#{LEAGUE}&tabs=1&tabIndex=0"); | |
req = Net::HTTP::Get.new(uri) | |
req['Cookie'] = "POESESSID=#{POESESSID}" | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
response = http.request(req).body | |
JSON.load(response)['tabs'].map{ |t| t['n'] } | |
end | |
def getTab(index) | |
uri = URI.parse("https://www.pathofexile.com/character-window/get-stash-items?accountName=#{ACCOUNTNAME}&realm=#{REALM}&league=#{LEAGUE}&tabs=0&tabIndex=#{index}"); | |
req = Net::HTTP::Get.new(uri) | |
req['Cookie'] = "POESESSID=#{POESESSID}" | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
response = http.request(req).body | |
JSON.load(response) | |
end | |
def colourize(str) | |
s = str | |
COLOURINGS.each do |n, colour| | |
s = s.gsub(/\b#{n}\b/i, '\0'.send(colour)) | |
end | |
s | |
end | |
contents = getTab getTabs.index TABNAME | |
stations = contents['items'].filter{ |i| i['typeLine'] == 'Horticrafting Station' } | |
all_horticrafts = stations.map{ |b| b['craftedMods'] }.flatten | |
horticrafts = Hash.new{ |h,k| h[k] = Array.new}.tap do |h| | |
all_horticrafts.each do |c| | |
craft, level = c.match(/(.*) \((\d+)\)/).captures | |
h[craft] << level.to_i + 10 | |
end | |
end | |
horticrafts.keys.sort.each do |craft, levels| | |
puts "#{colourize craft}: #{horticrafts[craft].sort.join(", ")}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment