-
-
Save m040601/626003 to your computer and use it in GitHub Desktop.
fetch gists/from user - very simple mechanize with arg
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 "rubygems" | |
| require "mechanize" | |
| @mechanize = WWW::Mechanize.new{|agent| agent.user_agent_alias = "Linux Mozilla"} | |
| STDOUT.sync = false | |
| def fetch_data(url) | |
| STDERR.puts "fetching #{url}" | |
| urls = @mechanize.get(url).search("a").map{|x| x['href']}; | |
| gists = urls.select{|x| x =~/^\/\d+$/}.map{|x| x[1..-1]} | |
| puts gists | |
| STDOUT.flush | |
| urls.select{|x| x =~ /^\/.+?page=/}[-1] | |
| end | |
| def fetch_gists(user) | |
| url = "http://gist.github.com/#{user}" | |
| while url = fetch_data(url) | |
| end | |
| end | |
| fetch_gists ARGV[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment