Marc Cramdal's blog

Monday, July 10, 2006

Kopete countdown script

Today is my first holiday day. So I wanted to have a countdown for my away message showing the time left before my holidays and then a nice "Vacances !!!!" (it's holiday in french) message.

To achieve this, I just wrote a little Ruby script this time. It's the first time I write such a big (!) Ruby script and it's very easy with some help.

So this is the result :
Image Hosted by ImageShack.us

And below you can find the script.


#!/usr/bin/ruby

require "time"

###### CHANGE SETTINGS HERE ######
# Can be any valid date time of the type : Wed Apr 09 08:56:04
time0 = String "15:00"

# Message before event occurs, use %% to put the number of hours left
message_before = String "%% heures avant (ip)"

# Message after event occurs. Same use of %% here. It will be a positive number of hours.
message_after = String "Vacances !!!!"

# Update the message every sleep_time seconds
sleep_time = Integer 60
#######

target = Time.parse(time0)

while true
current = Time.new
difference = target - current
hours = (difference.abs / 3600).floor;
minutes = ((difference.abs - hours*3600)/60).floor

# Format the number of hours left
time_left = String(hours) + ":" + sprintf("%02d",minutes)

if difference > 0 # If the event isn't past
`dcop kopete KopeteIface setAway "#{message_before.sub("%%", time_left)}" false`
else
`dcop kopete KopeteIface setAway "#{message_after.sub("%%", time_left)}" false`
break
end

sleep sleep_time;

end

2 Comments:

  • One of the serious shortcomings of the Kopete DCOP interface is that there's no way to look up your current status. You can lookup anyone's status with DCOP, except your own. Kind of awkward. :/

    By Blogger Bram, at 11:15 PM  

  • Salut,

    Il me semble que c'est toi qui a développé le script de statistiques. Si ce n'est pas le cas, ingore mon message ;-)

    En fait j'ai un bug qui fait que je ne peux pas consulter les statistiques. Le bug a déjà été reporté : mais n'a toujours pas été corrigé. Je suis sous Debian et j'utilise Kopete 0.12.4

    By Blogger Tom, at 11:18 PM  

Post a Comment

<< Home