Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish a countdown via gmail status?

Tags:

gmail

status

Please is it possible to publish a countdown in my gmail status? Like "01:44:15:23" and its decrements continually.

like image 824
sofo Avatar asked Jun 07 '12 15:06

sofo


2 Answers

Found a good article to share:

Google Talk uses XMPP then if you can connect using an XMPP client to your Google account you can use the client instead of Google talk.

The whole mechanism is too simple (Used the Smack XMPP Library because it is simple and serves me well):

  1. Login.
  2. Calculate difference between now and the targeted date.
  3. Send the presence

Login

import org.jivesoftware.smack.XMPPConnection;

public void connect() {
    XMPPConnection connection = new XMPPConnection(server); //Server is gmail.com for Google Talk.
    connection.connect();
    connection.login(username, password); //Username and password.
}

Calculate difference between now and the targeted date

This process is done using Java Calendar and Date objects:

import java.util.Calendar;
import java.util.Date;

{
        Calendar calendar1 = Calendar.getInstance();
        Date d = new Date();
        calendar1.setTime(d);

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(endLine); //End line is the date we're counting to.

        long milliseconds1 = calendar1.getTimeInMillis();
        long milliseconds2 = calendar2.getTimeInMillis();
        long diff = milliseconds2 - milliseconds1;

        long diffDays = diff / (24 * 60 * 60 * 1000);
        diff = diff % (24 * 60 * 60 * 1000);

        long diffHours = diff / (60 * 60 * 1000);
        diff = diff % (60 * 60 * 1000);

        long diffMinutes = diff / (60 * 1000);
        diff = diff % (60 * 1000);
}

This code calculates the difference between the two dates in days, hours and minutes.

Send the presence

After calculating the difference all we have to do is to send the presence:

import org.jivesoftware.smack.packet.Presence;

{
         String remaining = Long.toString(diffDays) + " day(s), " + Long.toString(diffHours) + " hour(s), " + Long.toString(diffMinutes) + " minute(s) " + message; //Message is usually: Until "something".

        Presence presence = new Presence(Presence.Type.available);
        presence.setStatus(remaining);
        presence.setPriority(24); //Highest priority in Google Talk
        presence.setMode(presenceMode); //This is one of XMPP modes (Available, Chat, DND, Away, XA).
        connection.sendPacket(presence);
}

After this point people will see your new status instead of the one in Google Talk. (Notice that you won’t be able to see the change inside Google Talk but rest assured it is changed.f you wanna make sure it is changed ask one of your friends to tell you your status).

like image 104
Zaheer Ahmed Avatar answered Sep 21 '22 08:09

Zaheer Ahmed


Its very simple just download status-counter.jar from here and write a script file

java -jar /root/status-counter.jar -status SF -username [email protected] -password XXXXXX -datetime 2013-03-21T16:00:00+02:00 -type hours -decimals 0

and write a cron to do the job

*/5 * * * * /path/script.sh > /dev/null

this updates your status every 5 minutes. More details can be found here.

like image 34
Cyril Avatar answered Sep 19 '22 08:09

Cyril