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:1e8e1c75f17be33868c710abada517ab233da0c5
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. 2 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. 1 entries are tagged with math
  34. 3 entries are tagged with mix
  35. 1 entries are tagged with motivation
  36. 1 entries are tagged with moving
  37. 2 entries are tagged with music
  38. 1 entries are tagged with newserver
  39. 1 entries are tagged with obama
  40. 1 entries are tagged with oil
  41. 1 entries are tagged with productivity
  42. 1 entries are tagged with radio
  43. 1 entries are tagged with rails
  44. 3 entries are tagged with recipe
  45. 1 entries are tagged with redmine
  46. 2 entries are tagged with reflections
  47. 1 entries are tagged with rmine
  48. 8 entries are tagged with ruby
  49. 1 entries are tagged with salmon
  50. 1 entries are tagged with salsa
  51. 1 entries are tagged with shoutcast
  52. 3 entries are tagged with site
  53. 2 entries are tagged with snow
  54. 1 entries are tagged with spill
  55. 1 entries are tagged with spotmanradio
  56. 1 entries are tagged with streamtranscoder
  57. 1 entries are tagged with tecate
  58. 1 entries are tagged with thanksgiving
  59. 6 entries are tagged with travel
  60. 1 entries are tagged with trip
  61. 1 entries are tagged with turkey
  62. 3 entries are tagged with twitter
  63. 1 entries are tagged with website
  64. 2 entries are tagged with work
  65. 1 entries are tagged with x4200
  66. 3 entries are tagged with yz250

Twitter Updates

Links to check out

Subscribe RSS