I had some code fun in September creating the Five Card Stories site, which provides a simple activity in visual storytelling by making a visitor select from five rounds of randomly chosen images to string together as a story told only in pictures — now the source code is available from Google Code (I would have liked to call it alpha version 0.0000001).

I designed it somewhat general, as I had two different ways I thought of getting images- one from pulling ones from a given tag in flickr and the other were taken from ones submitted at the Learning 2.008 Conference in a ning forum.

The source code provides what you need to run the flickr version. On my site, there are now 516 photos people have tagged to share and as I write this, there are 290 stories that people have created and saved on the site– alot of them I think came from an NMC conference where Ruben Puentadora shared it.

This was very fitting, since it was Ruben’s workshops on comics and storytelling that lit an idea the way use ran an activity based on Five Card Nancy.

A tricky part was the finding a way to get info from flickr on images of a specified tag. Either the API does not provide it, or I just don’t know enough about APIs (the latter most likely), but I could not figure out that route to get the info on photos of a specified tag. A twitter post got me a big boost from John Krutsch, who wrote some PHP that grabbed the info basically by saving as giant text variable the results of a flickr search query on the tag, and then parsing that into an array for the data needed (URL for image, name of photographer, and link to original flickr photo page).

John’s code worked as advertised, but at a run-time cost- the time to do the query and extract was at least 20 seconds, causing the web page that was handing out the cards to appear to be a sleeping dealer. My end around was to create a caching approach– I modified the code so when it searched, it output the array data to a text file, and on the next search, if the modified timestamp on the cache file was less than 70 minutes, it used the cache instead of taking the time to run a new query.

This still meant around once an hour, or at least next time a human visitor went to the sit, there would be a delay to get fresh images if the cache was “stale”. So my approach was to run an hourly cron script to do the search and update the cache file (the web server running the query does not care if it has to wait 30 seconds for data). Therefore a user of the site would always be fetcing the cached data, which at most is an hour old.

The code is moderately commented, but follows my own PHP pretzel logic. I am sure someone could code it much more elegantly (and I’ll roll in elegant mods), but I just posted the whole web site, code, and database set up at http://code.google.com/p/fivecardflickr/, released for free under GPL.

I have no idea if it makes sense, so I am hoping there are some eager beta testers (people with their own web servers and can manage basic PHP/MySQL stuff) who can try out the setup and see if they can get it running on another site, maybe with a different tag set then I used. I am not going to be surprised if something is wonky.

There’s nothing like the smell of code in the morning….

The post "Now Available: Source Code for Five Card Flickr" was originally pulled charred and crispy from a smoky charred oven at CogDogBlog (http://cogdogblog.com/2008/10/source-code-five-card-flickr/) on October 22, 2008.

No comments yet.

Leave a Comment

All fields are required. Your email address will not be published.