Created
August 19, 2018 15:42
-
-
Save jamie/9756bcce34767953efb5f34f6d125f2c 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
<?xml version="1.0" encoding="utf-8"?> | |
<ArrayOfBasicSetCollectionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<BasicSetCollectionInfo> | |
<SetName>Classic</SetName> | |
<Cards> | |
<CardInCollection> | |
<AmountNonGolden>2</AmountNonGolden> | |
<AmountGolden>0</AmountGolden> | |
<CopiesInDecks>0</CopiesInDecks> | |
<DesiredAmount>0</DesiredAmount> | |
<CardId>CS1_069</CardId> | |
</CardInCollection> | |
<CardInCollection> | |
<AmountNonGolden>2</AmountNonGolden> | |
<AmountGolden>0</AmountGolden> | |
<CopiesInDecks>0</CopiesInDecks> | |
<DesiredAmount>1</DesiredAmount> | |
<CardId>CS1_129</CardId> | |
</CardInCollection> |
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
require 'json' | |
require 'http' | |
require 'nokogiri' | |
DECKS = JSON.parse(HTTP.get('https://hsreplay.net/analytics/query/list_decks_by_win_rate/?GameType=RANKED_STANDARD&RankRange=LEGEND_THROUGH_TWENTY&TimeRange=CURRENT_EXPANSION'))['series']['data'] | |
CARDS = JSON.parse(HTTP.get('https://api.hearthstonejson.com/v1/25770/enUS/cards.collectible.json')) | |
wanted_cards = {} | |
{ 219 => 'Odd Rogue', | |
216 => 'Odd Paladin', | |
134 => 'Zoo Warlock', | |
179 => 'Spell Hunter', | |
139 => 'Deathrattle Hunter', | |
137 => 'Midrange Hunter', | |
26 => 'Midrange Shaman', | |
36 => 'Control Priest', | |
}.each do |archetype, deck_name| | |
print deck_name | |
DECKS.each do |_hero,decks| | |
decks. | |
sort_by{|d|d['total_games']}.reverse. | |
select{|d| d['archetype_id'] == archetype}. | |
first(8). | |
each do |deck| | |
print '.' | |
JSON.parse(deck['deck_list']).each do |card_db_id, count| | |
card_id = CARDS.detect{|card| card['dbfId'] == card_db_id}['id'] | |
wanted_cards[card_id] ||= 0 | |
wanted_cards[card_id] = [wanted_cards[card_id], count].max | |
end | |
end | |
end | |
puts | |
end | |
`cp Collection_Default.xml Collection_Default_#{Time.now.strftime('%Y%m%d%H%M%S')}.xml` | |
doc = File.open('Collection_Default.xml') { |f| Nokogiri::XML(f) } | |
builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml| | |
xml.ArrayOfBasicSetCollectionInfo('xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance", 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema") do | |
(doc/'BasicSetCollectionInfo').each do |set| | |
xml.BasicSetCollectionInfo do | |
xml.SetName (set/'SetName').text | |
xml.Cards do | |
(set/'CardInCollection').each do |card| | |
xml.CardInCollection do | |
xml.AmountNonGolden (card/'AmountNonGolden').text | |
xml.AmountGolden (card/'AmountGolden').text | |
xml.CopiesInDecks (card/'CopiesInDecks').text | |
xml.DesiredAmount(wanted_cards[(card/'CardId').text] || 0) | |
xml.CardId (card/'CardId').text | |
end | |
end | |
end | |
end | |
end | |
end | |
end | |
File.open('Collection_Default.xml', 'w') do |f| | |
f.puts builder.to_xml | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment