You know you’re a helplessly geek if you do what I just did XD

OK, everyone knows I have a thing for VIVA telecom which I vowed to boycott in the near future (Couldn’t do it sooner due to personal issues).

Few days ago, I went to VIVA to cancel all my subscriptions (A data line and a voice line). And apparently, I have to do the following:
* Wait for 65 days starting the day of cancelling my roaming service to cancel my voice line
* Wait January 18th to cancel my data line since January’s bill have been issued. I mean, I can cancel it but I’ll have to wait till January, so I might as well just wait\abuse.

So, what a better way to remind myself of the days left other than having it in my calendar, downloading countdown apps\softwares? Yep, write a a PHP bot to countdown the tweets XD

Steps to follow to make this happen:
1. Create a developer account
2. Create an application
3. Fill down the fields
4. Copy the “Consumer key” and “Consumer secret” and paste it in a notepad. Or just keep the page there because you’ll need those.
5. Download this (Or this if the latest release didn’t work)
6. Extract it to whatever folder you desire
7. Edit “config.php” file and replace CONSUMER_KEY\CONSUMER_SECRET with the values I told you to keep’em aside
8. Make a new file called “tweet.php” in the same folder where you extracted the zip file you downloaded in step #6 (Use whatever name you like)
9. Copy paste this code:

<?php
session_start();
require_once(‘twitteroauth/twitteroauth.php’);
require_once(‘config.php’);

if (empty($_SESSION[‘access_token’]) || empty($_SESSION[‘access_token’][‘oauth_token’]) || empty($_SESSION[‘access_token’][‘oauth_token_secret’])) {
header(‘Location: ./clearsessions.php’);
}

$access_token = $_SESSION[‘access_token’];

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token[‘oauth_token’], $access_token[‘oauth_token_secret’]);

$today = date(“d-m-Y”);
$enddate = date(“d-m-Y”, mktime(0, 0, 0, 1, 31, 2011)); //End date is formatted like this: (hour, minute, second, month, day, year). Please refer to http://php.net/manual/en/function.mktime.php for more details

$daysleft = abs(strtotime($enddate) – strtotime($today));

$tweetstr = ‘Only ‘ . floor($daysleft/(60*60*24)) . ‘ day’;
if ($daysleft > 1)
{
$tweetstr .= “s YOUR MESSAGE HERE”;
}
else if ($daysleft == 1)
{
$tweetstr .= ” YOUR MESSAGE HERE”;
}

$content = $connection->get(‘account/verify_credentials’);
$content = $connection->post(‘statuses/update’, array(‘status’ => $tweetstr));
?>

10. Upload the whole folder to wherever you like
11. Cron job it like this:

00 9 * * * wget http://www.link.to.your.website.com/link.to.your.folder/tweet.php

Replace 9 with the hour you’d like it to tweet (Server local time, not your local time).

And thats it, you’re done 😀

This tutorial enlightened me (Doing it blindly had some issues, had to think a bit).

This is just a funny workaround until I make a full real countdown tweeter at my convenience (In other words, whenever I feel like it). Had to do a PHP one because I’m in a hurry 😛

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.