Redmine2Twitter with isgd
- Posted: 1 year ago
- Tags:ruby, twitter
- 0 comments
So as it goes, there were a couple bugs, so I took the opportunity to fix them, and also add some additional features. In this revision we include more of the redmine message that goes along with the activity update as permitted, and then we run the direct link to the redmine page through is.gd for each issue and attach this to the tweet. Additionally I quickly optimized things and made it send is.gd https urls to redmine for my convenience. You can check it out on the second page.
#!/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
Comments:
| No Comments Posted |
Add Comment:
Back
