Instgram for Crowdsourcing Postbox Locations

Update: Its become an all India postbox data collection project. Now we use the tag #openpostboxindia. The source code is open sourced and can be used for any type of photo and location based data collection using Instagram and Twitter.

I have been using instagram a lot. If you follow me on instagram you would have noticed pictures of postboxes. If you check the details they all have a similar tagging pattern. They all are tagged with #openbangalore #openpostboxindia #postbox and #pin<pin_code>. The last tag #pin<pin_code> in real will look like #pin560100. All these pictures belong to my secret project called postboxes.

I like sending post cards. It's such a pain to send post card because its difficult to find a postbox. There aren't many these days. So for last few months I had been taking geo tagged pictures thinking one day I will clean them up. But that never happened.

But then instagram gave me an option to collect and organize this data in a fun way. I jumped into it. So now I instagram a post box with #openbangalore #postbox and #pin<pin_code>. I also geo tag them. I have a script which uses the instagram API and pulls the image url,Tags, Location, Time, User credits out of it. Cleans up that data and inserts into a SQLite database.

Now I am waiting for the database to build. I am planning to write a web app where you can search for a postbox depending on location or pincode. Of course I will make the DB available at OpenBangalore once we reach minimum data.

Contribute: If you live in Bangalore and use instagram.
1. Please take picture of postbox using instagram
2. Tag it with #openbangalore #openpostboxindia #postbox and #pin<pin_code> where &l;tpin_code> is real pincode
3. Geo tag it before submitting

If you are interested in running similar project in your city. You can do that too. Use the following code pull the data. Change the tag #openbangalore to something that makes sense for your city.

function startswith4($haystack, $needle) {
    return strpos($haystack, $needle) === 0;

$instagram_api_clinet_id = 'register at instagram to get one';
$instagram_api_url = ''.$instagram_api_clinet_id;

    /*** connect to SQLite database ***/

    $dbh = new PDO("sqlite:pb.sqlite");
    echo "Handle has been created ......\n<br>";

catch(PDOException $e)
    echo $e->getMessage();
    echo "\n<br>Database -- NOT -- loaded successfully .. ";
    die( "\n<br>Query Closed !!! $error");

$ch = curl_init ($instagram_api_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_close ($ch);
$data = json_decode ($json,true);
   //echo 'sucess';
   $picture_dicts = $data['data'];
   foreach($picture_dicts as $pic){
	    $tags 			= implode(', ', $pic['tags']);
	    $pincode 		= 0;
	    foreach($pic['tags'] as $tag){
	    	if(startswith4($tag, 'pin')){
	    		$pincode = substr($tag,3,10);
	    $lat 			= $pic['location']['latitude'];
	    $lan 			= $pic['location']['longitude'];
	    $created_time 	= $pic['created_time'];
	    $picture_url 	= $pic['images']['standard_resolution']['url'];
	    $post_id 		= $pic['id'];
	    $username 		= $pic["user"]["username"];
        $website 		= $pic["user"]["website"];
        $caption		= $pic["caption"]["text"];
		//check if post_id exists, if yes then go to next one. else insert
		echo "\n<br>Processing the post_id=".$post_id;
			$q = 'select count(*) as count_posts from post_box where post_id="'.$post_id.'"';
			//print '\n'.$q; 
			$count_posts = 0;
			foreach ($dbh->query($q) as $row){
	        	$count_posts = $row['count_posts'];

	        if ($count_posts == 0){
	        	print "\n<br>Lets INSERT";
	        	$i = 'insert into post_box( post_id , picture_url , tags , lat , lan , created_time , username , website,pincode, caption) values('.'"'.$post_id .'","'.$picture_url .'","'.$tags .'","'.$lat .'","'.$lan .'","'.$created_time .'","'.$username .'","'.$website .'","'.$pincode .'","'.$caption .'"'.')';
	        	//print $i;
	        	$count = $dbh->exec($i);
	        	print $count;
	        	print "<br>already exists";

			echo "\n<br>couldnt get into db";


4 Responses

  1. Shweta says:

    Remembered we had spoken about this. Will try to do it and add to the database :) Gorgeous and simple idea!

  2. Sanjay Nayak says:

    Wonderful project Thej! Keep up the good work.

  3. gls says:

    grt idea maga… sure it will b useful, will try my best to contribute.

  1. August 26, 2013

    […] Instagram Post Box Project – Help map Indian postboxes using Instagram […]