• No results found

5.5 WSh Scripting Language Design

5.5.3 Semantics

This section describes the WSh scripting language semantics through navigating some Web command examples, showing various functionalities of the language and the behaviour of Web commands when executed.

5.5.3.1 Basic Web Commands

This simple Web command pipeline will return the first 10 links from a Google search result page, using Egypt as the search keyword, and auto loop to get all images available via each result URL.

The pipe operator ‘|’ will connect the $STDOUT from the command on the left side with the $STDIN of the command on the right side.

The semicolon character ‘;’ indicates the end of command pipe sequence. It allows a pipeline to be written on multiple lines. When a user presses enter after writing ‘;’ the Web commands are executed and the result displayed on the Web browser. 5.5.3.2 New Web command example:

1 2 3 4 5 6 7

new googleWordCount ($searchWord){ $str1 = "found ";

$str2 = " times";

google $searchWord | fetch | txt | find $searchWord | count > $i; echo $searchWord $str1 $i $str2; }end;

1 2

google -10 "Egypt" | fetch | getImages;

Line 1: new, marks the beginning of a new command definition named googleWordCount. If the name already exists, the system will generate an error message.

The left parenthesis ‘(’ marks the start of the parameters list, where $searchWord is the parameter that is needed by the command. The right parenthesis ‘)’ marks the end of the parameters list. Finally, the left curly bracket ‘{’ marks the start of the Web command code block

Line 2: $str1, defines a variable. The ‘=’ assignment operator, assigns the value on the right side to a variable on the left side. The string value “found ” is surrounded with double quotes. The semicolon ‘;’ is used to terminate a statement. Line 3: this has similar semantics to the second line.

Lines 4, 5: This is a Web2Sh pipeline, starting with the google command that is executed using the value of $searchWord as its input parameter. The command returns a list of items each representing a link returned by Google search. Then the pipe loops over all returned links to fetch them. The following Web command, txt, filters the html tags keeping only the text content of the Web page. The result is forwarded to the find Web command, which return all lines where $searchWord is found.

google $searchWord | fetch | txt | find $searchWord | count > $i; Web2Sh executes the pipeline in the following order:

19. google: use Google’s search engine to search for the given term. 20. fetch: all URLs returned as the search result.

21. txt: pipe the page to the ‘txt’ command which strips all the tags and codes and leaves only the text content of the page

22. find: The result is piped to find command, which finds the occurrences of the search word inside the text and returns a list of items.

23. pipe the result of the find Web command to the count Web command which returns the number of times the search word was found inside the text Line 6: echo $searchWord + #str1 + $i + #str2 + $xurl;

This statement will print to the default output (user’s browser) the concatenated string.

Line 7: This is the close curly brace for the end of new command. ‘end;’ is used to finish the ‘new’.

5.5.3.3 Artwork Importer, iTunes Example:

This command will use an XML file called ‘iTunes library’; this will need to be uploaded to any online Web address and then it will extract the value of each album name and artist name. This will be used to build a search string for Google images to try to retrieve the album artwork. The first three images of each album search will be saved to a folder with the album name.

When the user chooses to create a new Web command, the script is saved to his private disk space on the Web2Sh server. Then the command can be called by the user assigned name space. For example, eoe.egNews;

All returned images are added to a zip file and downloaded to the user machine. After the command, finishes all the saved data on the server are automatically erased. For example for this entry:

<dict>

<key>Track ID</key><integer>42</integer>

<key>Name</key><string>Sandra - Don't Cry</string> <key>Artist</key><string>Sandra</string>

<key>Album</key><string>18 Greatest Hits</string> <key>Kind</key><string>MPEG audio file</string>

... </dict>

This search phrase will be generated:

"Here by Me" + "3 Doors down" + "Seventeen Days" + “Album”

1 3 4 5 6 7 8 9 10 11 12 13

/* param $iTunesMusicLibrary : is the URL for the iTunes Music Library XML file.*/

new iTunesArt($iTunesMusicLibrary){ $list = XPath $iTunesMusicLibrary “/plist/dict/dict”;

$list | find “ <key>Name</key>” | getTagValue “ <string>” | $songNames; $list | find “ <key>Artist</key>” | getTagValue “ <string>” | $artistNames; $list | find “ <key>Album</key>” | getTagValue “ <string>” | $albumNames;

Echo $songName, $artistName, $albumName, “album” | gImages -3 | Zip “artwork/” + $albumName;