Permalink
Browse files

basically it works, spits out page of gems

  • Loading branch information...
0 parents commit 3d1e62cd943292187b8f7400e46c647585889f34 @daveheitzman committed Mar 17, 2012
Showing with 127 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +8 −0 Gemfile
  3. +2 −0 README
  4. +1 −0 Rakefile
  5. +8 −0 bin/gemqs
  6. +7 −0 config/config.yml
  7. +24 −0 gemqs.gemspec
  8. +70 −0 lib/gemqs.rb
  9. +3 −0 lib/gemqs/version.rb
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,8 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in gemqs.gemspec
+gemspec
+
+gem 'mechanize'
+gem 'nokogiri'
+gem 'rainbow'
2 README
@@ -0,0 +1,2 @@
+ Gem Quicksearch
+
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
+#! /usr/bin/env ruby
+require File.expand_path("../../lib/gemqs.rb",__FILE__)
+
+include Gemqs
+
+scraper=Scraper.new
+scraper.get_page
+
@@ -0,0 +1,7 @@
+#
+# Configuration for gem quick search (gemqs)
+#
+
+---
+urls:
+ rubygems: http://rubygems.org
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "gemqs/version"
+
+Gem::Specification.new do |s|
+ s.name = "gemqs"
+ s.version = Gemqs::VERSION
+ s.authors = ["Dave Heitzman"]
+ s.email = ["daveheitzman@yahoo.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "gemqs"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
@@ -0,0 +1,70 @@
+require File.dirname( __FILE__ )+"/gemqs/version"
+require 'mechanize'
+require 'nokogiri'
+require 'open-uri'
+require 'yaml'
+
+module Gemqs
+ CONFIGURATION_FILE= File.dirname(__FILE__) + "/../config/config.yml"
+ def conf
+ if !@conf then
+ f=File.open CONFIGURATION_FILE
+ @conf = YAML::load( f )
+ @conf[:query]=''
+ @conf
+ else
+ @conf
+ end
+ end
+
+ class Scraper
+ def initialize
+ puts "gem quicksearch -- using url: " + conf["urls"]["rubygems"]
+ case ARGV.size
+ when 0
+ puts "usage: gemqs [search terms] "
+ else
+ query=ARGV.join("+")
+ # query = "/search?utf8=\u2713&query="+query
+ query = "/search?query="+query
+ conf[:query] = query
+ end
+
+ puts "url to be sent as a search "+conf['urls']['rubygems']+conf[:query]
+ end
+ def agent
+ @agent=Mechanize.new
+ end
+ def html_page
+ @html_page ||= Nokogiri::HTML( open( conf['urls']['rubygems']+conf[:query] ) )
+ #~ @html_page = Nokogiri::HTML( open('http://www.handsonnetwork.org/actioncenters/handsonconnect') )
+ end
+ def get_page
+ if conf[:query].size > 0
+ rpage=html_page #agent.get conf['urls']['rubygems']+conf[:query]
+ #~ puts rpage.inspect
+ # rpage.links.each do |l| puts l.text if l.text.include? "\n" end
+ #~ rpage.links.each do |l| puts l.inspect end
+ ritems = rpage.css('div.gems.border>ol>li')
+ ritems.each do |rli|
+ #~ puts "num of chidlren "+rli.children.size.to_s
+ rli.children.each_with_index do |item,index|
+ # puts index.to_s + ": " + item.text
+ #puts item.to_s.split("\n").inspect
+ end
+ # gem_name_and_version=rli.children[3].css("strong").text.to_s
+ #puts txt.first + txt.last + rli[0].to_s.split[0].to_s
+ puts rli.children[1].text.to_s + rli.children[3].text.split("\n")[1]+rli.children[3].text.split("\n")[2]
+ #~ puts "gem_name_and_version "+gem_name_and_version
+ #~ puts rli.children[3].text.split("\n").inspect
+ end
+ end
+ end
+ end
+
+ class Organizer
+ end
+ #Mechanize.new
+
+ # Your code goes here...
+end
@@ -0,0 +1,3 @@
+module Gemqs
+ VERSION = "0.0.1"
+end

0 comments on commit 3d1e62c

Please sign in to comment.