Skip to content

Instantly share code, notes, and snippets.

@cowboyrushforth
Created April 29, 2009 02:18
Show Gist options
  • Save cowboyrushforth/103538 to your computer and use it in GitHub Desktop.
Save cowboyrushforth/103538 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
gem 'feedtools'
gem 'htmltokenizer'
require 'feed_tools'
require 'html/htmltokenizer'
require 'twitter'
require 'net/http'
#your redmine url
feed_url = "http://redmine.YOURDOMAIN.com/projects/activity?format=atom&key=YOURRSSKEY"
twitter_username = TWITTER_USERNAME
twitter_password = TWITTER_PASSWORD
#since we are attaching 3 ...
#and then isgd, which is 17 or 18
#and some spaces
max_tweet_length = 117
#grab redmine data
feed = FeedTools::Feed.open(feed_url)
post_these = Array.new
#fetch salient pieces from this stream
feed.items.each do |act|
#only care about things that happened in
#the past 3 minutes, 10 seconds
if act.time >= 190.seconds.ago
tweet = "#{act.title}"
t = HTMLTokenizer.new(act.description)
desc = String.new
#run the redmine tags through
#html tokenizer
while token = t.getTag('p')
desc << t.getTrimmedText('p').gsub(/\n/, ' ')
end
#assemble the tweet
tweet << ": " << desc << " "
if tweet.length > max_tweet_length
tweet = "\t#{tweet[0..max_tweet_length]}..."
end
#fetch the isgd shortened url
isgdurl = ""
Net::HTTP.start( 'is.gd', 80 ) do |http|
isgdurl << http.get( "/api.php?longurl=#{act.link.gsub(/http/, 'https')}" ).body
end
tweet << isgdurl
post_these << tweet
end
end
#connect to twitter if we need to
if post_these.size > 0
twitter = Twitter::Base.new(twitter_username, twitter_password)
end
#post the oldest first
for tweet in post_these.reverse
status = twitter.post(tweet)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment