Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created July 10, 2012 21:33
Show Gist options
  • Save FiXato/3086375 to your computer and use it in GitHub Desktop.
Save FiXato/3086375 to your computer and use it in GitHub Desktop.
Simple script to get the number of games for a couple of old retro-computersystems
#!/usr/bin/env ruby
# encoding: utf-8
# (c) 2012, Filip H.F. "FiXato" Slagter
# For http://www.msx.org/forum/msx-talk/general-discussion/shame-you-dutch-collectors#comment-199093
# Suggestions for more lists: http://en.wikipedia.org/wiki/Category:Video_game_lists_by_platform
require 'open-uri'
require 'nokogiri'
def look_for_table_title(node,count=0)
prev = node.previous_element || node.parent
return false if prev.nil?
return prev.css('.mw-headline').text if prev.name == 'h2'
count += 1
return false if count == 15
look_for_table_title(prev,count)
end
puts "Spectrum:"
puts '-'*80
total = 0
%w[http://en.wikipedia.org/wiki/List_of_ZX_Spectrum_games].each do |url|
doc = Nokogiri::HTML(open(url))
puts doc.title
doc.css('.wikitable').each do |t|
if tt = look_for_table_title(t)
puts ' %s' % tt
end
count = (t.css('tr').size - 1) #-1 to get rid of the header row
total += count
puts ' %4i' % count
end
end
puts '='*20
puts 'Total: %4i' % total
puts
puts "Atari:"
puts '-'*80
total = 0
%w[http://en.wikipedia.org/wiki/List_of_Atari_2600_games http://en.wikipedia.org/wiki/List_of_Atari_7800_games].each do |url|
doc = Nokogiri::HTML(open(url))
puts doc.title
doc.css('.wikitable').each do |t|
if tt = look_for_table_title(t)
print ' %s:' % tt
end
count = (t.css('tr').size - 1) #-1 to get rid of the header row
total += count
puts '%4i' % count
end
end
%w[http://en.wikipedia.org/wiki/List_of_Atari_5200_games].each do |url|
doc = Nokogiri::HTML(open(url))
sublists = doc.css('div#mw-content-text/ul')
puts '%s: %4i' % [doc.title, sublists.css('li').size]
sublists.each do |t|
if tt = look_for_table_title(t)
print ' %s:' % tt
end
count = t.css('li').size
total += count
puts '%4i' % count
end
end
puts '='*20
puts 'Total: %4i' % total
puts
puts "Commodore 64:"
puts '-'*80
total = 0
%w[http://en.wikipedia.org/wiki/List_of_Commodore_64_games_%28A%E2%80%93M%29 http://en.wikipedia.org/wiki/List_of_Commodore_64_games_%28N%E2%80%93Z%29].each do |url|
doc = Nokogiri::HTML(open(url))
print ' %s:' % doc.title
count = doc.css('div.column-count/ul/li').size
total += count
puts ' %4i' % count
end
puts '='*20
puts 'Total: %4i' % total
puts
puts "Amiga:"
puts '-'*80
total = 0
%w[http://en.wikipedia.org/wiki/List_of_Amiga_games:_A-H http://en.wikipedia.org/wiki/List_of_Amiga_games:_I-O http://en.wikipedia.org/wiki/List_of_Amiga_games:_P-Z].each do |url|
doc = Nokogiri::HTML(open(url))
print ' %s:' % doc.title
count = doc.css('div#mw-content-text/ul/li').size
total += count
puts '%4i' % count
end
puts '='*20
puts 'Total: %4i' % total
puts
puts "MSX:"
puts '-'*80
total = 0
%w[http://en.wikipedia.org/wiki/List_of_MSX_games].each do |url|
doc = Nokogiri::HTML(open(url))
puts '%s:' % doc.title
doc.css('div#mw-content-text//ul')[1..4].each do |t|
if tt = look_for_table_title(t)
print '%13s:' % tt
end
count = t.css('li').size
total += count
puts ' %4i' % count
end
end
puts '='*20
puts 'Total: %4i' % total
puts
total = 0
puts "Using http://www.generation-msx.nl/msxdb Software Library:"
[1, 2, 4, 8].each do |system|
url = "http://www.generation-msx.nl/msxdb/index.php?url=%2Fmsxdb%2Findex&op=search&orderby=title&order=ASC&maxrows=25&title=&developer=&developer_select=-1&publisher=&publisher_select=-1&system=#{system}&game_code=&year=&rmedium=&sound=&kind=&genre=&max_players=&max_simultaneous=&software_language=&licence=&unreleased=&is_compilation=&takeru=&has_screenshots=&has_translations=&has_covers=&has_pokes=&has_cheats=&has_tips=&has_passwords=&has_maps=&days=&from="
doc = Nokogiri::HTML(open(url))
system_element = doc.xpath("//td[@class='text'][text()='System']").first
next if system_element.nil?
system_title = system_element.next_element.next_element.css('img').first['title']
count = doc.xpath("//td[@class='text'][starts-with(text(),'Found')]").text.split[1].to_i
total += count
puts '%12s: %4i' % [system_title, count]
end
puts '='*20
puts 'Total: %4i' % total
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment