Skip to content

Instantly share code, notes, and snippets.

@juno
Created June 13, 2012 16:17
Show Gist options
  • Select an option

  • Save juno/2925042 to your computer and use it in GitHub Desktop.

Select an option

Save juno/2925042 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'open-uri'
require 'nokogiri'
def get_anime_titles_in(year)
url = "http://ja.wikipedia.org/wiki/Category:#{year}%E5%B9%B4%E3%81%AE%E3%83%86%E3%83%AC%E3%83%93%E3%82%A2%E3%83%8B%E3%83%A1"
titles = []
open(url, 'r:UTF-8') do |body|
doc = Nokogiri::HTML(body)
doc.css('#mw-pages .mw-content-ltr li a').each do |elem|
title = elem.content
next if title =~ /\A\d+年のテレビアニメ/
titles << title
end
end
titles.sort
end
if ARGV.size < 1
puts "Usage: #{$0} from_year [to_year]"
exit
end
from = ARGV[0]
to = ARGV[1] || from
(from..to).each do |year|
titles = get_anime_titles_in(year)
titles.each { |i| puts "#{i},#{year}" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment