#!/usr/bin/env ruby # # Posts plan updates to Twitter. Run from cron. Plan file should be in # the form: # # 1283526618 Friday, September 3 2010 @ 08:10:18 AM # Blah blah blah blah blah # ------------------------------------------------------------------------ require 'twitter' require 'pathname' OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE PLAN = Pathname.new( ENV['HOME'] ) + '.plan' MAXSIZE = 280 ### Send the most recent plan updates to twitter. ### def main last_update = File.open( '.plit-lastupdate' ).read.chomp.to_i client = Twitter::REST::Client.new do |config| config.consumer_key = '' config.consumer_secret = '' config.access_token = '' config.access_token_secret = '' end updates.sort_by{|k,v| k }.each do |update| time, text = update next if time <= last_update puts "Posting #{time}..." client.update( text ) last_update = time end open( '.plit-lastupdate', 'w' ) do |f| f.puts last_update end end ### Fetch all current .plan updates and return them ### as a hash { id => text } ### def updates return PLAN.read.split(/^-{10,}\r?\n/).inject({}) do |hash, update| post = update.match(/ ^(\d+) # update id (epoch) .+\r?\n # human readable date (.+) # update text /xm) next hash unless post text = post[2].chomp text = text[0, MAXSIZE-3] << '...' if text.size > MAXSIZE hash[ post[1].to_i ] = text hash end end main if __FILE__ == $0