Revisions
-
udonchan revised this gist
May 3, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -24,12 +24,12 @@ def open_cache? end def open_cache @cache = open('cache', 'wb') unless open_cache? end protected :open_cache def write_cache open_cache @cache.puts(Marshal.dump(@l)) end protected :write_cache -
udonchan revised this gist
May 3, 2010 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ class Results @l = nil @cache = nil def initialize c = open('cache', 'r') @@ -47,5 +47,7 @@ def results(q) end end r = Results::new puts r.results('沢城みゆき') r.close -
udonchan revised this gist
May 3, 2010 . 1 changed file with 37 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,23 +4,48 @@ require 'open-uri' class Results @l = nil @cache =nil def initialize c = open('cache', 'r') begin @l = Marshal.load(c.read) rescue Exception @l = Hash::new ensure c.close end end def open_cache? @cache != nil end def open_cache @cache = open('cache', 'wb') end protected :open_cache def write_cache open_cache unless open_cache? @cache.puts(Marshal.dump(@l)) end protected :write_cache def close @cache.close if open_cache? end def results(q) if @l[q] == nil @l[q] = open(URI.parse(URI.encode("http://www.google.gr/search?hl=en&q=#{q}")), 'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.4) Gecko/20100413 Firefox/3.6.4').read.scan(/Results <b>1<\/b> - <b>10<\/b> of about <b>(.*)<\/b> for <b>/).first.first.gsub(',', '').to_i write_cache end @l[q] end end puts Results::new.results('沢城みゆき') -
udonchan revised this gist
May 3, 2010 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,21 @@ class Results def Results.results(q) cache = open('cache', 'r') begin l = Marshal.load(cache.read) rescue Exception l = Hash::new ensure cache.close end if l[q] == nil cache = open('cache', 'wb') l[q] = open(URI.parse(URI.encode("http://www.google.gr/search?hl=en&q=#{q}")), 'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.4) Gecko/20100413 Firefox/3.6.4').read.scan(/Results <b>1<\/b> - <b>10<\/b> of about <b>(.*)<\/b> for <b>/).first.first.gsub(',', '').to_i cache.puts(Marshal.dump(l)) cache.close end l[q] end end -
udonchan created this gist
May 3, 2010 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'uri' require 'open-uri' class Results def Results.results(q) open(URI.parse(URI.encode("http://www.google.gr/search?hl=en&q=#{q}")), 'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.4) Gecko/20100413 Firefox/3.6.4').read.scan(/Results <b>1<\/b> - <b>10<\/b> of about <b>(.*)<\/b> for <b>/).first.first.gsub(',', '').to_i end end puts Results::results('沢城みゆき')