Created
September 9, 2013 13:27
-
-
Save commuterjoy/6495563 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'rubygems' | |
require 'trollop' | |
require 'json' | |
require 'cgi' | |
require 'rest_client' | |
require 'time' | |
CONF = Trollop::options do | |
opt :since, "Seconds elapsed between now and the publication date", :type => :int, :required => true, :short => "-s" | |
end | |
class ContentApi | |
def initialize | |
@host = 'http://content.guardianapis.com/search?format=json&page-size=50' | |
end | |
def recently_published(since = 60) # seconds | |
JSON.parse(RestClient.get(@host).body)['response']['results'].select { |result| | |
(Time.now.gmtime - Time.parse(result['webPublicationDate']).gmtime).to_i < since | |
} | |
end | |
end | |
class OpenGraph | |
def initialize | |
@host = 'https://developers.facebook.com/tools/debug/og/object' | |
end | |
def ping(resource) | |
RestClient.get(@host, { :params => { :q => CGI::escape(resource) }}) | |
end | |
end | |
# ---- | |
ContentApi.new.recently_published(CONF.since).each { |item| | |
puts item.to_json | |
puts OpenGraph.new.ping(item['webUrl']).body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment