Created
September 28, 2012 21:47
-
-
Save billsaysthis/3802239 to your computer and use it in GitHub Desktop.
OSX terminal script to post tweets to a WordPress blog
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 'rubygems' | |
# https://github.com/nu7hatch/gmail | |
require 'gmail' | |
# https://github.com/sferik/twitter | |
require 'twitter' | |
def mail_tweet(gmail, tid, subj) | |
if !gmail.logged_in? | |
p "Not logged in" | |
return | |
end | |
msg = gmail.compose do | |
to "Your Secret WordPress email address" | |
subject subj # some subject is necessary, otherwise WP makes the post title a timestamp | |
# body content assumes you use a category named Tweets for these | |
# also, publicize is off since this might create loop of post -> tweet -> post -> tweet ad infinitum | |
body "[tweet " + tid.to_s + "][category Tweets][comments off][publicize off]" | |
end | |
msg.deliver! | |
puts "Delivered mail for tweet " + tid.to_s | |
end | |
gmail = Gmail.connect('Your Gmail address', 'Your Gmail password') | |
Twitter.configure do |config| | |
config.consumer_key = 'Your Twitter consumer keu' | |
config.consumer_secret = 'Your Twitter config secret' | |
config.oauth_token = 'Your Twitter oauth token' | |
config.oauth_token_secret = 'Your Twitter auth token secret' | |
end | |
tweets = Twitter.user_timeline("Your Twitter username") | |
faves = Twitter.favorites("billsaysthis") | |
now = Time.new | |
start = Time.mktime(now.year, now.month, now.day, 0, 0, 0) # today midnight | |
# use reverse_each since Twitter returns in reverse chronological order | |
# And we want to post oldest first | |
tweets.reverse_each do | tw | | |
if tw.created_at > start | |
mail_tweet(gmail, tw.id, "A Tweet") | |
end | |
end | |
faves.reverse_each do | tw | | |
if tw.created_at > start | |
mail_tweet(gmail, tw.id, "I Favorited a Tweet") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment