Sha256: 5f751da10ebff72e9ff0e43375a5311be34879588097776b82d81ba96a59b614
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
require 'open-uri' require 'nokogiri' require 'hashie' require 'thor' require 'json' module KickstarterCurl class Cli < Thor desc 'metadata', 'Fetches metadata (number of backers, amount pledged, etc.) related the specified Kickstarter project' option :url, :required => true, :desc => 'URL of the Kickstarter project' option :csv_file, :desc => "File to save metadata to as CSV" def metadata() metadata = Hashie::Mash.new metadata.queried_at = Time.now url = options[:url] doc = Nokogiri::HTML(open(url)) metadata.url = url metadata.backers = doc.css('*[data-backers-count]').attr('data-backers-count').value.to_i metadata.pledged = doc.css('*[data-pledged]').attr('data-pledged').value.to_i puts metadata.to_hash.to_json # optionally save CSV if csv_output = options[:csv_file] File.open(csv_output, 'a') do |f| f.puts [metadata.queried_at, metadata.backers, metadata.pledged, metadata.url].join(', ') end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
kickstarter_curl-0.0.2 | lib/kickstarter_curl/cli.rb |
kickstarter_curl-0.0.1 | lib/kickstarter_curl/cli.rb |