/
pikebot
executable file
·30 lines (26 loc) · 906 Bytes
/
pikebot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
require 'twitter'
require 'feedjira'
module Pikebot
# Feed Setup
url = "http://jonathanpike.net/feed.xml"
feed = Feedjira::Feed.fetch_and_parse(url)
entry = feed.entries.first
# Twitter Setup
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["TWITTER_CONSUMER_KEY"]
config.consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
config.access_token = ENV["TWITTER_ACCESS_TOKEN"]
config.access_token_secret = ENV["TWITTER_ACCESS_TOKEN_SECRET"]
end
# If a blog post has been published in the last hour
# publish the title and link to Twitter
if __FILE__ == $0
if Time.now.utc - entry.published <= 3600
client.update("#{entry.title}: #{entry.url}")
puts "Updated Twitter! Your last Tweet was '#{entry.title}: #{entry.url}'"
else
puts "No new posts to Tweet about!"
end
end
end