Skip to content

Instantly share code, notes, and snippets.

@cronin101
Last active December 15, 2015 14:49
Show Gist options
  • Save cronin101/5276864 to your computer and use it in GitHub Desktop.
Save cronin101/5276864 to your computer and use it in GitHub Desktop.
Cheating at pokemon battles.
#!/usr/bin/env ruby
require 'httparty'
require 'nokogiri'
def info_page_html_for(pokemon)
reponse = HTTParty.get "http://bulbapedia.bulbagarden.net/wiki/#{pokemon}_(Pok%C3%A9mon)".force_encoding('UTF-8')
end
def weakness_table_for(pokemon)
table = info_page_html_for(pokemon)
table = table.split('Under normal battle conditions in Generation V').last
table = table.split('Weak to').last
table = table.split('Immune').first
table = table.split('</tbody>').first
Nokogiri::HTML.parse(table).xpath("//span[@style='display:inline-block;']").map(&:text).map { |string| string.split[0] }
end
cached = {}
while true do
puts 'Which Pokémon are you fighting?'
pokemon = gets.chomp.capitalize
puts "\n\nYou should use one of the following:\n #{cached[pokemon] ||= weakness_table_for pokemon}\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment