Redmine2Twitter with isgd

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:

Your Name:
Your E-Mail:
(Not Displayed)
Comment:
Security Code:9055826a8d07d28d50962e443fe6ca3bd41be34a
Type Security Code:


Back

Tag cloud

  1. 1 entries are tagged with 2007
  2. 1 entries are tagged with 2008
  3. 1 entries are tagged with 2009
  4. 1 entries are tagged with 2010
  5. 2 entries are tagged with applevalley
  6. 1 entries are tagged with archlinux
  7. 1 entries are tagged with artichoke
  8. 1 entries are tagged with automation
  9. 1 entries are tagged with batcountry
  10. 1 entries are tagged with beats
  11. 1 entries are tagged with bigsur
  12. 3 entries are tagged with bm2009
  13. 8 entries are tagged with burningman
  14. 1 entries are tagged with christmas
  15. 5 entries are tagged with code
  16. 1 entries are tagged with cplusplus
  17. 1 entries are tagged with desert
  18. 1 entries are tagged with drinks
  19. 1 entries are tagged with dspam
  20. 2 entries are tagged with dunes
  21. 1 entries are tagged with energy
  22. 1 entries are tagged with esplanade
  23. 5 entries are tagged with europe
  24. 1 entries are tagged with evdo
  25. 2 entries are tagged with flv
  26. 1 entries are tagged with gadgets
  27. 1 entries are tagged with government
  28. 1 entries are tagged with haiku
  29. 1 entries are tagged with icecast
  30. 1 entries are tagged with internetradio
  31. 1 entries are tagged with iphone
  32. 2 entries are tagged with losangeles
  33. 3 entries are tagged with mix
  34. 1 entries are tagged with motivation
  35. 1 entries are tagged with moving
  36. 2 entries are tagged with music
  37. 1 entries are tagged with newserver
  38. 1 entries are tagged with obama
  39. 1 entries are tagged with productivity
  40. 1 entries are tagged with radio
  41. 1 entries are tagged with rails
  42. 3 entries are tagged with recipe
  43. 1 entries are tagged with redmine
  44. 2 entries are tagged with reflections
  45. 1 entries are tagged with rmine
  46. 8 entries are tagged with ruby
  47. 1 entries are tagged with salmon
  48. 1 entries are tagged with salsa
  49. 1 entries are tagged with shoutcast
  50. 3 entries are tagged with site
  51. 2 entries are tagged with snow
  52. 1 entries are tagged with spotmanradio
  53. 1 entries are tagged with streamtranscoder
  54. 1 entries are tagged with tecate
  55. 1 entries are tagged with thanksgiving
  56. 6 entries are tagged with travel
  57. 1 entries are tagged with trip
  58. 1 entries are tagged with turkey
  59. 3 entries are tagged with twitter
  60. 1 entries are tagged with website
  61. 2 entries are tagged with work
  62. 1 entries are tagged with x4200
  63. 3 entries are tagged with yz250

Twitter Updates

Links to check out

Subscribe RSS