Auto Retweet Bot for Twitter

July 24, 2010 | PHP | , , , , ,

This simple tutorial will show you how to create a simple (ro)bot that will re-tweet (RT) any particular tweets related to your search results in Twitter. In this example, my bot will re-tweet any tweet that contain “wahihi” word, so I name it Kingdom of Wahihi.

Before we start, we need following requirements:

  • Twitter accountYes, the bot needs its username and password.
  • PHP interpreterYou can put this script in your own machine or any web hosting services that supports PHP.
  • Cron JobCron is an application to execute a job (application/program) in schedule. Available on mostly any web hosting services.

As replacement for Cron Job, you can manually execute the script by visiting the page (open the script using web browser).

Step one, create the bot. I’ts a PHP script, if you’re an alien and never heard of this programming language before, I recommend you to skip this page and visit my other stories shown in the sidebar.

Let’s start with declaration of username and password of your Twitter account:

<?php
$user = 'kingdomofwahihi';
$pass = 'password';
?>

Then grab the keyword:

<?php
$search = "http://search.twitter.com/search.atom?q=wahihi";
$xml_source = file_get_contents($search);
$x = simplexml_load_string($xml_source);
?>

Above script will fetch search results of “wahihi” from Twitter’s search. The output from Twitter is in Atom (XML) format, so it’s easier for us to read the data using simplexml_load_string() function.

Next, extract the data and retweet them:

<?php
foreach($x->entry as $item){
   // part one
   $author_name = $item->author->name;
   list($name, $mbuh) = explode (" ",$author_name);
   $author = trim($name);
   $msg = 'RT @'.$author. ': ' .$item->title;

   // part two
   $out = "POST http://twitter.com/statuses/update.json HTTP/1.1\r\n"
   ."Host: twitter.com\r\n"
   ."Authorization: Basic ".base64_encode ($user.':'.$pass)."\r\n"
   ."Content-type: application/x-www-form-urlencoded\r\n"
   ."Content-length: ".strlen ("status=$msg")."\r\n"
   ."Connection: Close\r\n\r\n"
   ."status=$msg";

   // part three
   $fp = fsockopen ('twitter.com', 80);
   fwrite ($fp, $out);
   fclose ($fp);
}
?>

I divide above lines of code into three parts because they have different task. Part one, the bot will grab author’s name/username and what he/she tweeted then join them into one variable. And add a RT sign as a re-tweet mark.

Part two, we are preparing the variable that we will sent to Twitter’s server, it contains raw HTTP header. I know this bot is gross, but is robust :P

Part three, open socket to Twitter’s server on port 80 then send the raw HTTP header we have prepared on part two. Now check Twitter to see if your bot is successful.

Leave any comment if you have any questions, but question about how to execute the script won’t be answered :p

Update, September 3rd:
This script is no longer working since Twitter changed its authentication method. You can try this script with OAuth authentication, written by Nazieb.

13 comments


Wild Fruit On The Roadside

June 26, 2010 | Daily | , , ,

It was early morning and I was walking from the town into my house, it’s about 30 minutes walking distance. In the middle of the trip and after the sunrise, I saw this fruit on the roadside.

Wild fruit and its leaves

I didn’t know what fruit is that. It looked delicious, remind me of the wild marquisa I found on the riverside some years ago –when I was a child. Before I picked the fruit to try how is the taste, I took some pictures of that fruit.

Later, I peeled that strange fruit carefully and found a disgusting form of the pulp. Without trying its taste, I knew that no way this fruit will be delicious.

disgusting pulp

But I couldn’t resist to try it, so I licked its black pulp and there’s almost no taste.  Just cold and tasteless so I threw it away and continue my walk.

Soft fur on its rind

I use Panoramio to publish those images, if you wonder where did I get that fruit, you can click on the image(s) above and there is a map (Google Maps) that show you where the pictures were taken.

7 comments


Insert French Characters Into MySQL

June 4, 2010 | PHP | , , , ,

I was developing a bi-lingual website, so my custom CMS should be able to accept and display both English and non English characters. For English characters, it’s a piece of cake. But for French characters, I have pulling my hair for days to find out what went wrong with my script.

I have set the database to use UTF-8 encoding, but every time I inserted the text it’s messed up. French characters become a horror, unreadable for everyone.

After several days –literally– I have found the solution: I must set the character set into UTF-8 right before I insert the data!

< ?php
mysql_query("SET CHARACTER SET utf8"); //<--the key!
mysql_query("insert into data values ('$french_chars')");
?>

SET CHARACTER SET utf8 will tell MySQL to store the inserted data using UTF-8 encoding. And it works for me.

4 comments


Wrong mail quota in CPanel

May 9, 2010 | Technical Stuffs | , , , ,

Today I found my CPanel displays wrong disk quota for an email account. It shows 58/100 MB (58 MB used, of 100 MB preserved) while actually the mailbox is empty.

I have checked with du -sh command (a command to check disk usage) and it returned 100 KB or something, so there must be something wrong.

After googling around, I got some trick to solve this problem. Perform this action from shell/SSH or simply using file manager in CPanel:

  1. Go to /home/usercpanel/mail/domain.com/emailaccount/.
  2. Delete file named maildirsize, this file stores disk usage information
  3. Change the number of disk quota for that email account from CPanel (inside menu Email Accounts), it will regenerate a new maildirsize file.

Refresh your browser and now you should see the correct disk quota for that email account.

1 comment


SmadAV – At a Glance

April 16, 2010 | Reviews | , , , ,

SmadAV is a local antivirus made by Indonesia youths that I’ve heard since some times ago but just now I get the chance to give it a try. Here is the screenshoot,  very simple with all tools in a single modal dialog (click to zoom the pic).

The interface is likely different than any other antivirus, very simple and contains all what we need when the computer is under attack by the viruses.

Some viruses will disable access to msconfig, regedit and task manager that make us difficult to restore the computer. And SmadAV provides button to access msconfig, regedit and task manager in a single click. Cool!

I would like to say that SmadAV is made by experienced people, I mean, experienced with the virus problem.  Maybe that’s why they include all the tools to kill virus in a single application.  It’s like having a swiss tool knife for all your virus problems.

Although I haven’t use SmadAV on my daily basis, it’s a recomended one. They said that after give some donations, we can get a license key to unlock some more features, like faster scanning and automatic updates.

No comment


Create PDF Files For Free

April 11, 2010 | Technical Stuffs | , ,

I was wondering why many people still using Adobe Acrobat for creating PDF files from their documents. It’s bloated –or you can say my computer is too old– and of course expensive! Some minutes ago I’ve checked the price on their website, it costs US$ 299.

Why don’t people find an alternative PDF-maker software which is free and lightweight? I know that you can get any serial number from Internet for Adobe Acrobat to turn that pricey software into a free one. But hey, it’s like stealing from a kid’s pocket.

A few days ago –when I needed a software to convert my documents into PDFs– I found doPDF which is free and lightweight. And most of all, it doesn’t require any Ghostscript installation just like any other PDF printers.

cap-0109

Perhaps it doesn’t have all the features you want and requires you to upgrade to the paid version but it’s enough for me. Awesome PDF printer.

This way I thank to doPDF developer(s) for their great work.

No comment


Redirect Old URLs to New URLs

April 3, 2010 | Technical Stuffs | , , ,

When we have a completely new website and uses different CMS, there will be old URLs that already spread everywhere on the Net. Discarding old URLs is not an option because we will lost visitors from search engines. So we must redirect all old URLs into new URLs.

Using redirect in .htaccess is great, but when your old URLs contain question mark, most likely it will fail to redirect.

Following code will work:

redirect 301 /old-url.html http://domain.com/new-url.html
redirect 301 /very-old.html http://domain.com/very-new.html

But following code will –at least in my case– failed:

redirect 301 /file.php?age=old http://domain.com/new-url.html
redirect 301 /file.php?age=old&id=12 http://domain.com/very-new.html

Luckily there’s 404 directive from Apache using .htaccess. We can mix the power of custom 404 page with PHP to perform this directions stuff. Here’s how to mix them up:

Create custom 404 page using .htaccess

ErrorDocument 404 /redirect.php

Then create file redirect.php with following contents:

< ?php
$req = trim($_SERVER['REQUEST_URI']);
switch($req){
	case "/file.php?age=old":
		$goto = "http://domain.com/new-url.html";
	break;
	case "/file.php?age=old&id=12";
		$goto = "http://domain.com/im-very-new.html";
	break;
	default:
		$goto = "http://domain.com";
}
header ("HTTP/1.1 301 Moved Permanently");
header ("Location: $goto");
?>

By this method, old URLs that are no longer exist are forwarded to our custom 404 page (named redirect.php) and that redirect.php will bring visitors to new URLs.

Nice, isn’t it?

2 comments


How Many Facebook Users from Indonesia?

February 17, 2010 | Out Of Topics | , ,

How many do you think the number of Facebook users from Indonesia? Thank God, Facebook have a nice tool to find out.

fbmember

Practically, you can also see how many lesbians, gays and other cool stats. Only if the users are honest :P

2 comments


Disposable Email Address

February 14, 2010 | Reviews | , , ,

Some website require us to provide an email address in order to use their service(s), even if we only use their service once in a lifetime. Say you want to download a hardware driver for your computer from a website but they ask you to fill up your email address so they can send you the download link. Giving your email address away? You don’t have to.

one way mail

You can use any free disposable email address service such as onewaymail.com, it’s very easy to use. When the website asks your email, simply fill any (yes, any) email address that came into your mind. Let’s say driver@onewaymail.com.

The next thing you do is visit onewaymail.com and type driver in the field box located at the top page then press Go button. Now you should see an email from the website where you can download the driver.

Piece of cake, isn’t it?

4 comments


My first GPS device, iGotU GPS Logger

November 27, 2009 | Reviews

A few days ago I received a free giveaway from My Digital Life, a small GPS device: i GotU GPS Logger.

i-GotU GPS LoggerI soon opened the package and found the contents are:

- GPS device
- white strap/belt
- data/power cable
- CD driver and applications

The color is all white, remind me of any Apple’s products and the GPS device is pretty small.  It made sense because the device is used for logging and receiver only, and there’s only one button for various operation: power on/off, tracking, pairing with bluetooth and else.

The strap helped me to attach GPS logger on my arm, bag, or any place where I want to attach. I also found a USB cable that I can use to charge the battery and transfer log file from GPS into my laptop/PC.

While the CD contains driver and application named @Trip PC. With this app I can automatically geotag photos, track my journey and view it on the maps etc.

When I tried to track myself, the result is pretty good. I can measure how far I go, my speed and altitude. Despite the manual said to put the device directly toward the sky (to gain better satellite signal), it still worked great although I hide the receiver under my jacket.

Now I can’t wait to go out  for some outdoor activities. A hiking, maybe.

4 comments