Browse files

Update open.markdown

  • Loading branch information...
1 parent bc55922 commit a5c2d4b4fa1bb417eca2a9cc8ba4a26b1df63218 @killme2008 killme2008 committed Mar 25, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 clojure_toolbox.rb
View
17 clojure_toolbox.rb
@@ -22,19 +22,24 @@ def initialize(name,url)
end
def fetch_project_url(url)
+ begin
open(url).read.scan(/<a href="(.*)">\1<\/a>/)[0][0]
+ rescue
+ print "An error occurred when fetching #{url}: ",$!, "\n"
+ end
end
open("http://clojure-libraries.appspot.com/") do |http|
http.each_line do |line|
catalog="unknow"
- line.scan(/<a href="(\/(category|show)\/\d+)">(.*?)<\/a>/).each do |x|
- if x[1]=="category"
- catalog=x[2]
+ links=line.scan(/<a href="\/(cat|library)\/(.*?)">/) || []
+ links.each do |x|
+ if x[0]=="cat"
+ catalog=x[1]
libs[catalog]||=[]
- elsif x[1]=="show"
- detail="http://clojure-libraries.appspot.com#{x[0]}"
- libs[catalog] << Project.new(x[2].sub(/&raquo;&nbsp;/,""),fetch_project_url(detail));
+ elsif x[0]=="library"
+ detail="http://clojure-libraries.appspot.com/library/#{x[1]}"
+ libs[catalog] << Project.new(x[1].sub(/&raquo;&nbsp;/,""),fetch_project_url(detail));
end
end
end

0 comments on commit a5c2d4b

Please sign in to comment.