In my last post about the use of twitter, I said that my primary purpose for using twitter is to track my time. However twitter is not created for that use. It is very difficult to track your time using twitter. But there is an easy solution to this problem - create an offline twitter.
Twitter is a huge application - but offline twitter is not. The whole application is just 4 lines of PHP code. Yes - that's right - just 4 lines. And a database.
Database
The database is just one table(OT) with 3 fields. The simplest solution is often the best.
CREATE TABLE `OT` (
`id` int(11) unsigned NOT NULL auto_increment,
`status` varchar(255) NOT NULL,
`time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;
PHP Code
This code will be the entire application(if you can call it that). Just save this to a file called, say, OT.php
<?php
if(!$_REQUEST['status']) exit;
mysql_connect('localhost','root','pass') or die("Cannot connect to mysql Server");
mysql_select_db('Data') or die("No database called 'Data'");
mysql_query("INSERT INTO OT VALUES('','$_REQUEST[status]',NOW())");
If you want to use a database abstraction layer, be my guest. If you escape the $_REQUEST[status]
before using it in the query, by all means do so. But, the result will be the same. An offline twitter using just 4 lines of code.
Input
So, how does one enter new status into this system? By making a small modification to the command line twitter client...
curl --data-ascii "status=`echo $@|tr ' ' '+'`" "http://localhost/tools/OT.php"
curl --basic --user "<User>:<Password>" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json"
The first line will send the status to my PHP file and the second will send it to the twitter server. Now I have all the status in the database.
View the Contents
I have still not created an interface that will use this database to show my time useage. If I want to know something, I just open up phpMyAdmin and run an SQL query.
I know - this method is not for everyone. You need to be on linux to use my command line client. You must have a web server and a MySQL server running for this method to work. But if you are working on the LAMP platform, you will have this stuff ready.
Read More...