Created
July 18, 2016 15:57
-
-
Save rclavel/609e8321502015cabea28de840191ab1 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
require 'json' | |
require 'nokogiri' | |
require 'mechanize' | |
puts 'Get source' | |
agent = Mechanize.new | |
html = agent.get 'http://bulbapedia.bulbagarden.net/wiki/List_of_French_Pok%C3%A9mon_names' | |
nodes = Nokogiri::HTML.parse html.body | |
puts 'Parse html' | |
translations = {fr: {}, en: {}} | |
nodes.css('#mw-content-text > table > tr') | |
.select do |x| | |
x.children.count{|y| y.name == 'td'} == 4 | |
end.each do |x| | |
c = x.children.select{|x| x.name == 'td'} | |
code = c[0].text.strip | |
if code[/[0-9]/] | |
translations[:en][code.to_i] = c[2].text.strip | |
translations[:fr][code.to_i] = c[3].text.strip | |
end | |
end | |
puts 'Write pokemon.fr.json' | |
File.write 'pokemon.fr.json', translations[:fr].to_json | |
puts 'Write pokemon.en.json' | |
File.write 'pokemon.en.json', translations[:en].to_json | |
puts 'Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment