Skip to content

Instantly share code, notes, and snippets.

@Niall47
Created April 7, 2024 16:11
Show Gist options
  • Save Niall47/d98838648b6e08aafbe646184e076975 to your computer and use it in GitHub Desktop.
Save Niall47/d98838648b6e08aafbe646184e076975 to your computer and use it in GitHub Desktop.
capture all the combinations of pals for breeding
# frozen_string_literal: true
require 'capybara'
require 'capybara/dsl'
require 'selenium/webdriver'
Capybara.register_driver :firefox do |app|
Capybara::Selenium::Driver.new(app, browser: :firefox)
end
Capybara.default_driver = :firefox
Capybara.javascript_driver = :firefox
include Capybara::DSL
visit 'https://palbreed.com/breeding-tree'
pals = all('.name')
breeding = {}
# close the popups
within_frame('sp_message_iframe_1092512') { click_button 'More Options' }
within_frame('sp_message_iframe_978329') { click_button 'Save & Exit' }
begin
pal_index = 0
pal_names = pals.map(&:text)
# For every possible child pal
pal_names.each do |name|
# honestly this is so dumb, but the page doesn't show element 113 for some reason so we're skipping it
pal_index += 1 if pal_index == 112
puts "Pal: #{name} number #{pal_index}"
breeding[name] = []
pal_index += 1
find(:xpath,
"/html/body/div[@id='__nuxt']/div/section[@class='breeding-tree']/div[@class='left-panel']/div[@class='top']/div[@class='pals-list']/div[@class='pals']/div[@class='pal'][#{pal_index}]").click
# iterate through each combo card and load it into the hash under the pal name
combinations = all('.card')
combinations.each do |card|
# split the string into two names
parents = card.text.scan(/^(.+?)\s\+\s(.+?)$/)
next if parents[0].nil?
parent_1 = parents[0][0]
parent_2 = parents[0][1]
breeding[name] = breeding[name] << [parent_1, parent_2]
end
# Now we go back to the child pal list page thing
click_button 'Clear'
end
rescue StandardError => e
puts "Dont care #{e}"
end
# Save the breeding hash to a json file
File.write('pal_breeding.json', JSON.pretty_generate(breeding))
puts breeding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment