Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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