microformats/microformats-ruby

command line test tool

cweiske opened this issue ยท 3 comments

It'd be nice if there was a cli tool that I could pass an URL, and it would dump the extracted microformats.

Goal would be to have tool to quickly debug potential parsing problems.

jeena commented

Just something dirty here, when I have the time I will turn it into something I can commit as a CLI client which gets installed with the gem or something.

#!/usr/bin/env ruby

require 'microformats2'
require 'uri'
require 'net/http'
require 'openssl'
require 'json'

def get_source_html(source_uri)
        uri = URI.parse source_uri
        http = Net::HTTP.new(uri.host, uri.port)
        http.use_ssl = uri.port == 443
        http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        request = Net::HTTP::Get.new(uri.request_uri)
        begin
                return http.request(request).body
        rescue => e
                puts "Error: #{e}"
        end
end


unless ARGV[0].nil?
        html = get_source_html(ARGV[0])
        collection = Microformats2.parse(html)

        puts JSON.pretty_generate(JSON[collection.to_json.to_s])
else
        puts "usage: mf2.rb URL"
end

@jeena When you have time to write up something proper (and write some docs in the README), feel free to push it into master. ๐Ÿ‘๐Ÿป๐Ÿš€

Closing this issue as a new command line tool 'microformats' has been added in the latest release.