Created
May 18, 2014 01:57
-
-
Save odanado/1564ea76bdd44c4b4501 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
require "net/http" | |
require "uri" | |
require "json" | |
require "nokogiri" | |
require "open-uri" | |
#メガ進化はまだ | |
def to_ja(name) | |
uri = "http://bulbapedia.bulbagarden.net/wiki/#{name}_(Pok%C3%A9mon)" | |
doc = Nokogiri::HTML(open(uri)) | |
name_ja = doc.css('//span[@lang = "ja"]')[0].content | |
name_ja = "メガ" + name_ja if name.include?("mega") | |
return name_ja | |
end | |
$values = ["hp","attack","defense","sp_atk","sp_def","speed"] | |
def create_DB(index) | |
uri = URI.parse("http://pokeapi.co/api/v1/pokemon/#{index}/") | |
response = Net::HTTP.get_response(uri) | |
data = JSON.parse(response.body) | |
print to_ja(data["name"])+"," | |
$values.each do |ele| | |
print data[ele].to_s + "," | |
end | |
print "\n" | |
end | |
for i in 1..10 do | |
create_DB(i.to_s) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment