Categories
Development

Pulling Flickr photos using YUI Get Utility with photo_id

Atlantic Cape Community College has been using a Flickr Pro account to store and share our photos (Flickr Pro at $24.95/yr is a steal) and also like to incorporate those photos into our news releases from time to time. 

So I began working an a little script that would call the flickr.photos.getSizes API Method using YQL to return the info to display the photo (dimensions, source, etc.) in an easy to consume JSON object. Oh yeah, and also had to do all this using the YUI Get Utility since our server at the moment doesn’t have cURL installed.

So first I went to the YQL console (it’s awesome to be sure to check it out) to generate the HTTP to call the JSON we’re looking for using the flickr.photos.getSizes API Method. Here is the the YQL I fed it:

select * from flickr.photos.sizes where photo_id = "414195174"

and it gave me this wonderful REST Query (again YQL is awesome):

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.sizes%20where%20photo_id%20%3D%20%223591600467%22&format=json&callback=cbfunc

this returns the following JSON info:

cbfunc({
 "query": {
  "count": "6",
  "created": "2009-06-08T06:37:37Z",
  "lang": "en-US",
  "updated": "2009-06-08T06:37:37Z",
  "uri": "http://query.yahooapis.com/v1/yql?q=select+*+from+flickr.photos.sizes+where+photo_id+%3D+%223591600467%22",
  "diagnostics": {
   "publiclyCallable": "true",
   "url": {
    "execution-time": "149",
    "content": "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&photo_id=3591600467&page=1&per_page=10"
   },
   "user-time": "154",
   "service-time": "149",
   "build-version": "1678"
  },
  "results": {
   "size": [
    {
     "height": "75",
     "label": "Square",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1f25e40ce1_s.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/sq/",
     "width": "75"
    },
    {
     "height": "100",
     "label": "Thumbnail",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1f25e40ce1_t.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/t/",
     "width": "84"
    },
    {
     "height": "240",
     "label": "Small",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1f25e40ce1_m.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/s/",
     "width": "202"
    },
    {
     "height": "500",
     "label": "Medium",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1f25e40ce1.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/m/",
     "width": "420"
    },
    {
     "height": "1024",
     "label": "Large",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1f25e40ce1_b.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/l/",
     "width": "861"
    },
    {
     "height": "2400",
     "label": "Original",
     "media": "photo",
     "source": "http://farm3.static.flickr.com/2447/3591600467_1fe814e144_o.jpg",
     "url": "http://www.flickr.com/photos/accc_cr/3591600467/sizes/o/",
     "width": "2017"
    }
   ]
  }
 }
});

So now we have an easy to use REST Query to use with all the info that we just so happen to need from Flickr.

Now I needed to create a little Javascript using the YUI Get Utility to consume the REST Query that we just built.

Here’s a basic version of the script I wrote:

function jsonFlickrApi(rsp){
 
		if (rsp.query.count == 0){
			return;
		} else {
 
			var container = document.getElementById('article-photo');
 
			// create elements
 
			var photoAnchor = document.createElement('a');
			var photoImg = document.createElement('img');
 
			// set attributes
			photoAnchor.setAttribute('href', rsp.query.results.size[3].source);
			photoAnchor.setAttribute('rel', 'lightbox');
 
			photoImg.setAttribute('src', rsp.query.results.size[2].source);
			photoImg.setAttribute('width', rsp.query.results.size[2].width);
			photoImg.setAttribute('height', rsp.query.results.size[2].height);
 
			// append to DOM
			photoAnchor.appendChild(photoImg);
 
			container.appendChild(photoAnchor); 
 
		}
    }
 
    var objTransaction = YAHOO.util.Get.script("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.sizes%20where%20photo_id%20%3D%20%223591600467%22&format=json&callback=jsonFlickrApi");

The function jsonFlickrAPI gets called when the JSON has loaded since it’s sent along with the Get request as the callback function. Then we just check if anything has been returned from the REST call before proceeding by checking the count returned.

Then create some DOM nodes and attach them to a div in our HTML. That’s really about it.

Next, I’m going to improve this to pull all relevant photos with a certain tag(s) from our Flickr account to dynamically create relevant galleries.

Categories
Design Development

sjrates.com

sjrates.comJust finished up building www.sjrates.com. It’s a site that makes comparing local rates easy and convenient for those in Southern New Jersey.

The client approached with with a sound idea of making it easier for local people to compare rates. Instead of having to search each financial institution individually, he wanted to group them all together to save users time.

The site makes use of many technologies.  Notable uses include:

Working with the client was a real pleasure. I thought we had a great client – developer relationship and I this really helped contribute to a really nice finished project.

Categories
Adventure

Board of Trustees Dinner

I had to go to a Board of Trustees meeting for dinner and to be honored for winning the employee of the quarter award the other night. While it was really great to be voted by my co-workers for the award, I wasn’t really looking forward to hanging out with the Board. They’re all extremely nice, but I’ve never been that big on accepting awards. I shy up.

Had to shake a few hands, but pretty much knew most of the people there. A student and a faculty member were being honored as well, so it was nice to sit next to some people with a similar agenda as my own.

Food was good, ate lots of chicken then loaded up on some dessert thing that I probably could of done without. But it was a yummy treat and one that I couldn’t pass up. Once again I’d like to thank all those who took the time to vote for me. It is nice to be recognized by the people I work with. Plus the reserved parking spot did come in handy during commencement when I came back from lunch break.

Categories
Video Games

Punch Out!!

Punch Out!!I do believe I’m addicted to Punch Out!! for the Wii. Mike Tyson’s Punch Out!! for the NES has always been an all time favorite of mine, a true classic. So when I heard that a new version was due out for the Wii, I was both excited and concerned that it might not be possible for it to live up to the expectations that I had of the game. 

This game is a definite buy.  I actually woke up a little bit earlier on a work day just to sneak another shot at Don Fleminco.  Not sure I’ve done that in a while.  The controls are almost identical to the original, and it also supports the balance board, but I haven’t given that a shot yet.

Defending your title and the various boxer challenges give this game a lot of replay value. There’s a multiplayer mode, which seems pretty fun. The only drawback is no online play, but outside of that this game is a true masterpiece that manages to capture the fun I had back when it originally came out in 1987.

Categories
Design

What the Font?

Found a very cool and usefull iphone app called What the Font? It’s very cool. It’s a app that helps to identify a font.

So for instance, you take a photo using the iphone of a font.  You then crop the image so just the font in question is selected. It then uploads the font and processes it letter by letter and gives back a list of fonts that it think it might be. It takes a minute or so for the whole process, but that’s so much faster than it would take to go through the thousands of fonts I have installed.

So far it’s turned out to be pretty accurate and has helped New Guy Mike and myself figure out what font was used in some old print documents that were created before he worked here.

It’s a very cool app so check it out at the App Store, and oh yeah it’s free too.

Categories
Books

Head First Web Design

Just got done reading through Head First Web Design by O’Reilly. Borders was having a 20% off deal going, and I always like to read through beginner books every now and then to reinforce the basics. This is a great book to read if you’re getting started working on the web.

I’ve always been a big fan of the Head First series, they do an excellent job of visually explaining tech topics. Most tech books are either way too basic or much too advanced, but the Head First series are a pretty solid read. You will need to have a pretty good understanding of XHTML and CSS to get through this one.

I thought the book did a great job of explaining the following:

  • design
  • dealing with a client
  • information architecture
  • designing for your audience
  • using the color wheel
  • navigation
  • writing for the web
  • accessibility

If you’re new to web design or just need a good read on current best practices, I highly recommend this book.