Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line test tool #39

Closed
cweiske opened this issue Aug 30, 2016 · 3 comments
Closed

command line test tool #39

cweiske opened this issue Aug 30, 2016 · 3 comments

Comments

@cweiske
Copy link
Contributor

cweiske commented Aug 30, 2016

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
Copy link
Collaborator

jeena commented Aug 30, 2016

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

@veganstraightedge
Copy link
Contributor

@jeena When you have time to write up something proper (and write some docs in the README), feel free to push it into master. 👍🏻🚀

dissolve added a commit that referenced this issue May 19, 2017
This add the command-line tool 'microformats' which takes and input
html, url, or filepath.  It also works for piping input and output to
other command line tools.

Console based tests resulted in a few odd errors, made appropriate fixes
to absolute_uri for this.

Finally, version bump to 4.0.2
@dissolve
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants