Skip to content

Instantly share code, notes, and snippets.

@herestomwiththeweather
Last active June 7, 2016 16:59
Show Gist options
  • Save herestomwiththeweather/f73dec9fdaa2ed0821594192f4a93cfd to your computer and use it in GitHub Desktop.
Save herestomwiththeweather/f73dec9fdaa2ed0821594192f4a93cfd to your computer and use it in GitHub Desktop.
send_webmentions.rb
#!/usr/bin/env ruby
require 'rss'
require 'webmention'
require 'time'
string = File.open('latest_time.txt', 'r') { |f| f.read }
latest = string.strip # RSS timestamp of most recent blog post for which webmentions have been sent
latest_found = latest # RSS timestamp of most recent blog post including new ones found
last_time = Time.parse(latest)
rss = RSS::Parser.parse('http://herestomwiththeweather.com/feed.xml', false)
rss.items.each do |item|
t = Time.parse(item.pubDate.to_s)
if t > last_time
client = Webmention::Client.new item.link
sent = client.send_mentions
if t > Time.parse(latest_found)
latest_found = item.pubDate.to_s
end
end
end
if Time.parse(latest_found) > last_time
File.open('latest_time.txt', 'w') {|f| f.write(latest_found) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment