Batch Download of Photos From Flickr Based on Their Tag
For the FOSS.my event, I wanted everyone to tag their photos with foss.my or foss.my 2008. Because this makes it easier to easily see FOSS.my buzz as it happens on Flickr!
A Tale of Sucky Wordpress Plugins
I was looking for a plugin to grab Flickr photos by a specified tag, so that we can use it in the foss.my gallery. Though there are many Flickr plugins for Wordpress, there was none catered to my requirements. Unable to find a solution, I thought it was quicker to hack one myself.
So this script just expanded from there, and I quickly had a Flickr batch downloader.
[block:important]There are several requirements:
- Download phpFlickr, and unzip it to the same directory as the script.
- You need to obtain a Flickr API key.
[/block]
Use the source
<?
/*
* phpFlickr
* http://phpflickr.com/
*
* Flickr API
* http://www.flickr.com/services/api/
*
* Flickr API call flickr.photos.search
* http://www.flickr.com/services/api/flickr.photos.search.html
*
* Photos are available via the following format:
* http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg
*
* For more information visit http://www.flickr.com/services/api/misc.urls.html
*
* Applying for a Flickr API Key
* http://www.flickr.com/services/api/keys/apply/
*/
require_once("phpFlickr.php");
define('VERBOSE', array_search('-v', $argv));
// Download a batch of photos from the given page
function download($photos) {
$download = 0;
foreach ($photos['photo'] as $photo) {
$filename = sprintf("pics/%s-%s.jpg", $photo['owner'], $photo['id']);
$url = sprintf("http://farm%d.static.flickr.com/%s/%s_%s_o.jpg", $photo['farm'], $photo['server'], $photo['id'], $photo['secret']);
if (file_exists($filename)) {
if (VERBOSE)
print sprintf("33[33m %-10s %s33[0m \n", "Skip", $url);
else
print sprintf("33[33m.33[0m");
continue;
}
if (VERBOSE)
print sprintf("33[32;1m %-10s %s33[0m \n", "Download", $url);
else
print sprintf("33[32m.33[0m");
file_put_contents($filename, file_get_contents($url));
$download += 1;
}
return $download;
}
$flickr = new phpFlickr("YOUR_API_KEY");
$options = array('tags' => 'fossmy, "fossmy 2008", foss.my, "foss.my 2008"');
$photos = $flickr->photos_search($options);
print sprintf("Available 33[32;1m %d 33[0m \n", $photos['total']);
// Download the first batch of photos
$downloaded = download($photos);
$page = $photos['page'];
$pages = $photos['pages'];
// Download the following batch of photos
for ($i = 2; $i < $pages; $i++) {
$options['page'] = $i;
$photos = $flickr->photos_search($options);
$downloaded += download($photos);
}
if (! VERBOSE)
echo "\n";
print sprintf("Downloaded 33[32;1m %d 33[0m/ %d \n", $downloaded, $photos['total']);
Running it
It's just as a simple as:
[block:terminal]php download.php[/block]
Sample Results:
[block:terminal]
Available 492
..................[trim]............
Downloaded 0 / 492
[/block]
It even comes with a -v flag, so you can view what files are being downloaded.
code::XtremeApps:: 2007 Summary – EventPedia.sg
Well this is just a summary of a long post about my trip to Singapore, and the code::XtremeApps:: 2007 Programming Competition held there this past weekend. Don't expect the full blog post to come out anytime soon, though it is in draft.
This competition conflicted with the eGenting Programming Competition, so I had to make a decision. Have a chance at possibly winning first prize again at eGenting, or risk the safety net and go into uncharted territories (at least for me) that is Singapore, and push myself to the max.
Even though it's so very near this was my first time I visited Singapore, and I am quite impressed with it. They say the grass is always greener on the other side of the field, hell I think it actually does, at least the trees. But once again, this is just from a tourist perspective.
My team members for the competition were once again Kamal, and Kegan from the previous Rails Rumble competition. Together we formed Team RSB, the Ruby Super Brothers (*cough cough*)
Arriving in Singapore, Kamal and myself checked into Carlton Hotel, and lured by the prospects of free Internet, I plugged my beloved IBM laptop into the wall socket, powered it on, and left it alone, while I got comfortable in the hotel room. A few moments later, I returned to my laptop to find the screen completely blanked out. After several minutes of restarting, trying to resuscitate it, I came to the conclusion that it was dead.
My laptop died on arrival to Singapore. How great.
In fact when Kamal put his MacBook charger into the wall socket, it started omitting strange noises, and we deduced that the wall socket must have been faulty.
Later we went to Sim Lim, the Lowyat of Singapore (or so I've been told) looking on trying to isolate the problem, and have it fixed within the day. But that didn't go so well. The repair shop said the mobo was fried and there was not much else I can do about it.
After arriving back from Sim Lim, we talked to the hotel trying to get them to claim responsibility over a faulty wall socket, but that didn't work at all.
Luckily by the end of the day, I was able to borrow a laptop from Kamal's relative and setup a development environment on top of Windows Vista. That was also a first experience for me, using Windows Vista. I didn't have the liberty to install Ubuntu, as I didn't want to mess with the partitions, so I ran the server version in VMware Player. It was more trouble than it looks, perhaps when I release a verbose version of this trip, then you'll see.
Now I had to win first place. To repair my current laptop, and or buy a new one.
The code::XtremeApps:: competition lasted for 24 hour, and was held by the renowned (at least the University, don't know about the school) Singapore Management University School of Information Systems. The campus is really nice, with a very modern architecture.
There was a large number of participants, with over 80 participating teams consisting of 1-3 people each. Surprisingly there were quite a number of girls, and some nice/cute ones to boot. I also noticed that at least half of the participants were carrying MacBooks around, and some were wearing either WWDC shirts or Digg.
The theme for the competition was:
Hospitality and/or tourism services in a participative society.
"Participative society", well that must have flagged something! Social Networking!
Our Team came up with EventPedia.sg, an event aggregation with all the social networking features (save for folksonomy) site for Singapore. During the first round of judging I was quite thrilled that we were able to build a complete site in 24 hours. Minus the tests for it!
Bummed out after staying up for more than 32 hours, we decided to call it quits, and returned to our hotel room for some nice shut eye. But before we could even rest, or at least I couldn't (Kamal and Kegan were already in dreamland), we received a call saying we've made it to the second round of judging the next day. Now I could sleep easily.
I was told that the second round of judging consisted of only 5 teams, so we only had to beat 2 other teams to get third, and another 2 to get first. Victory was so near.
But shortly after arriving, we found out it was 11 teams. Damn. After the judging was completed, we had some time to kill before leaving Singapore, and went to Vivocity.
After arriving home at 11pm, I checked my email. An email from the organizers. We had won co-third place. That is there were 2 teams who had won third place. I quickly went to sleep after that, from a completely exhausting trip.
I am completely disappointed in myself.
Rails Rumble 2007: Reduxbook
Yes, I know this is a bit late, but a few weeks ago on the weekend of September 8th to the 9th, I participated in the first ever Rails Rumble competition. The goal of the competition was to build a Ruby on Rails application in 48 hours, basically the whole weekend. The prizes for Rails Rumble are really enticing. The winners are decided from the public voting for the best application.
Kamal, Kegan, and Sean and myself were camping out in RSB in Cyberjaya for most of the time. Found lunch and dinner there, though there really wasn't much to eat over there.
Our application idea was to build a contacts aggregator from the various services out there. Be it Twitter, Digg, Delicious, Flickr, or your very own blog feed. We dubbed it Reduxbook.
At the start, Kamal handled the server and setting up the continuous deployment via Capistrano. Sean covered the HTML markup and design. Kegan looked at integrating the services. As for myself I hacked away at application's source code.
The first few hours went okay, but as the 24 hour mark came by, we knew we were in a pinch. The last 24 hours was a real adrenaline rush, and it went by really really fast. But we were able to pull it through with an all nighter.
Don't forget to vote for Reduxbook !

