Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


Einstein - Flickr

  
Write a shell script to get images from Flickr and make a web page to display them.

Background


The script

Shell script usage:
 flickr (list of tags) 
Get latest images from the NLI (see above) tagged with these tags and make a web page to display them.
For example:
 flickr cork
 flickr dublin pub
 flickr dublin 1922
Send the output into this file:
 $HOME/flickr.html 
  

Einstein test environment

As explained before, in the special Einstein test environment, we need extension .sh and need to call it with "./" in front of it.
Also for technical reasons we will call it flickr3.
So the conclusion is that we need a file called flickr3.sh and we run it like this:
 ./flickr3.sh (list of tags) 

Setup

For this lab:


Getting started

Start with this skeleton:

# convert list of args (separated by spaces) into list separated by commas

TAGS=` echo $* | tr ' ' ',' `

# now use TAGS to construct the URL
  

Check with Einstein

Send your program to Einstein and see if you can get some initial marks.
You will need to output to the output file not the command line.
  

HTML snippets

  1. You will notice there are snippets of usable HTML inside here:
     "description": " HTML payload (encoded) ", 
  2. For each photo, we are going to extract the descriptions and the list of tags.
  3. You can use egrep to extract lines containing either X or Y using:
     egrep 'X|Y' 
  4. The patterns we want to look for are:
    "description":
    "tags":
    
  5. Your program will now be:

    TAGS=` echo $* | tr ' ' ',' `
    url=[construct URL]
    [wget command] | [egrep command]
    

  6. Test that your program now gets the feed, and extracts the descriptions and lists of tags, and nothing else.

  

Fix the snippets

  1. The descriptions are HTML snippets, encoded. Decode them to normal HTML.
  2. You can do this using tr to remove one character. What character?
  3. "tr" will generate a warning that you can ignore.
  4. Send to the output file.
  5. Your program will now be:

    TAGS=` echo $* | tr ' ' ',' `
    url=[construct URL]
    [wget command] | [egrep command] | [tr command] > [output file] 
    

  6. You can use a multi-line pipe.
  7. Now double click on the output page and you will actually see the images.

  

Final tidy

  1. It needs some tidying. Use sed to insert space before each item:
     sed "s|<p>|<hr style='margin-top:70'><h1> next photo </h1><p>|"  
    (This only puts space in front of the first <p> on each line.)

  2. Check it looks good. Upload to Einstein for marks.
  

Einstein is fussy

Note that for this test, Einstein is fussy.
Einstein expects each description line to be all on one line, and each tags line to be all on one line, and there be no other lines:
.. description line ...
.. tags line ...
.. description line ...
.. tags line ...

You can insert extra HTML on a line (like we did with the vertical space). But do not make new lines, or combine lines, with the version you send to Einstein, or Einstein will get confused.

  

After

  1. Yes you could do some more tidying up. There is some loose text that needs tidying up. You could make lots of improvements.
  2. You can tidy it up after Einstein gives you full marks, since Einstein is fussy.