- Posted: 2 years ago
- Tags:ruby, twitter
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.
Continue Reading -->
- Posted: 2 years ago
- Tags:code, productivity, redmine, twitter
What do you do when you have mail, instant messages, rss feeds, web pages, text messages and revision control to all keep up with? Myneid came up with an idea of getting redmine updates from within twitter, so I took a crack at it:
#!/usr/bin/env ruby
require 'rubygems'
gem 'feedtools'
gem 'htmltokenizer'
require 'feed_tools'
require 'html/htmltokenizer'
require 'twitter'
#your redmine url
feed_url = "http://redmine.yourcompany.net/projects/activity?format=atom&key=YOURRSSKEY"
#grab redmine data
feed = FeedTools::Feed.open(feed_url)
post_these = Array.new
#fetch salient pieces from this stream
feed.items.each do |act|
tweet = "#{act.title}"
t = HTMLTokenizer.new(act.description)
desc = String.new
unless ARGV[0].nil? or ARGV[0] != 'full'
while token = t.getTag('p')
desc << t.getTrimmedText('p').gsub(/\n/, ' ')
end
tweet << "\t#{desc[0..137]}..."
end
if act.time >= 5.minutes.ago
post_these << tweet
end
end
#connect to twitter if we need to
if post_these.size > 0
twitter = Twitter::Base.new('YOURTWITTERUSERNAME', 'YOURTWITTERPASSWORD')
end
#post the oldest first
for tweet in post_these.reverse
status = twitter.post(tweet)
end
Beware, this script has no real error checking, but as long as your credentials and access key are all correct it should be golden. You will need the feedtools, twitter, and html tokenizer gems to get it to run.
I run this from cron every 5 minutes. As long as the redmine server and the server that the cron is run from both have accurate system clocks it should work well. A more elaborate version some day may include more error checking and dupe checking.
Have fun out there.
- Posted: 3 years ago
- Tags:code, ruby, twitter
I always have a dozen terminals open, so I figured it was time to make a way to post to twitter from the command line. This is extremely simple and can probably be improved, but for now this is working for me:
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
if ARGV.size == 0
puts "\tUsage: tweet i like to eat cheese"
exit
end
#Load Configuration from ~/.twitter
begin
config = YAML::load(open(ENV['HOME'] + '/.twitter'))
rescue
puts "\tConfiguration File Missing"
puts "\tExample:\n\n"
puts "\tlogin: mylogin"
puts "\tpassword: mypassword"
puts "\n\tput in ~/.twitter\n"
exit
end
#initialize twitter library
twitter = Twitter::Base.new(config['login'], config['password'])
message = ARGV.join(' ').gsub(/"/, '')
status = twitter.post(message)
puts "\t\tTweet Posted: http://twitter.com/#{status.user.name}/statuses/#{status.id}\n"
Remember to 'gem install twitter' as root, or run as sudo, and also to put your configuration file in ~/.twitter. There is an example in the usage output of the script.
Update: I posted a new and slightly improved version of this for
Download here. This version will print out tweets for you if ran with no parameters, and will post any parameters you do use straight to twitter. Also, I found out that the twitter gem I am using already has a decent cli interface. Read about it
here.