Return to labs index

Assignment #2 - Image Searching with Perl
Due: February 7, 2008

Overview

You are asked to implement a tool to search www.flikr.com's library of images in PERL. In order to encourage you to become familiar with UNIX man pages, the details of the lab are given in a similar format. The lower portion of this document contains hints, including information about a powerful library that will help you to access the Web via PERL.

NAME

getimage - get images by keyword from www.flickr.com

SYNOPSIS

getimage [OPTION]... KEYWORD [KEYWORD ...]

DESCRIPTION

Query Flickr's Web site, by keyword, for images. Download images matching all provided keywords, saving them into the current working directory.

Saved files maintain their extension, but are named after the keywords, and enumerated, beginning with 0, in the order downloaded. For example, a query via the keywords "pony" and "hat" might result in the creation of the files "pony_hat_0.jpg" and "pony_hat_1.jpg".

The use of multi-word keywords is not support. For example, "George Washington" may only be expressed as two and'ed keywords, not an ordered tuple.

-n n

Optional argument limiting the number of results to, at most, n images. The default limit, absent this argument, is 10.
-t target_directory
Optional argument forcing files to be saved into the target_directory instead of the current working directory.

RETURN VALUE

Returns 0 on success, non-zero on any other condition. For example, returns 1 if the target directory does not exist.

EXAMPLES

getimage pony hat

Download up to 10 images matching both of the keywords "pony" and "hat", save them into the current working directory, and name them using the convention as follows: pony_hat_0.jpg, pony_hat_1.jpg, &c. The limit of at most 10 matching images is the default imposed in the absence of the -n flag, which defines a user-specified limit.

getimage -n3 pony hat

As above, but save no more than three (3) matches.

getimage -n3 -timage_files pony hat

As above, but place results into the "images files" subdirectory.

The LWP Library

We'll be using the get() and getstore() functions from the LWP library to interact with the Web site. The get() function requests a page by URL. The resulting object is returned as a string. The getstore() function has two arguments, the second of which provides the name of the file to which the object should be saved on disk.

The examples below illustrate these uses of get() and getstore(). In each of the examples below, please notice the "use LWP::Simple;" line. It is an tells PERL that we'll be using the Simple object from within the LWP library. The same form is used to include other libraries in PERL.

Example 1: Returning the page as a string

  #!/usr/bin/perl

  use LWP::Simple;

  $url = "http://www.google.com";
  print get($url);
  

Example 2: Storing the page into a file

  #!/usr/bin/perl

  use LWP::Simple;

  getstore('http://www.cmu.edu', 'cmu.html');
  
Implementation Hints
Hints:

We're Here To Help!

As always -- remember, we're here to help!