Last active
December 25, 2015 22:39
-
-
Save dummied/7051472 to your computer and use it in GitHub Desktop.
The guts of PinboardDigest, an OSX System Service to produce link roundup text based on Pinboard bookmarks as painlessly as possible.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/https' | |
require 'cgi' | |
require 'rubygems' | |
require 'json' | |
AUTH_TOKEN = "YOUR_AUTH_CODE_GOES_HERE" | |
NUMBER_OF_RESULTS = 10 | |
input = STDIN.read | |
starter = "https://api.pinboard.in/v1/posts/all?auth_token=#{AUTH_TOKEN}&results=#{NUMBER_OF_RESULTS}&format=json" | |
url = URI.parse(input != "" ? starter + "&tag=#{CGI.escape(input)}" : starter) | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # You should use VERIFY_PEER in production | |
request = Net::HTTP::Get.new(url.request_uri) | |
res = http.request(request) | |
result = JSON.parse(res.body) | |
text << "# Links for #{Time.now.strftime("%B %e ")}\n\n" | |
result.each do |link| | |
text << "* **[#{link["description"]}](#{link["href"]}):** #{link["extended"]}\n\n" | |
end | |
print text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment