clacker


Group: Members
Posts: 570
Joined: June 2004 |
 |
Posted: June 21 2006,15:29 |
 |
piccolo, I'd try using the wget command to get the contents of the web page and then use grep and possibly awk to trim it down into the parts you want. I would use pipes to feed the output of one command into the input for another and string them together to do what you want.
wget can send a web page's source to the standard output if you use the -O - switch like so:
wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O -
Now you can look at the text and see what the lines you want have on them. I noticed they contain a time, so we can use grep to print only lines that have a time on them by "piping" the output from the wget command into the grep command using a | symbol:
wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O - | grep "[0-9][0-9]*:[0-9][0-9]*:[0-9][0-9]*"
You can further narrow down the lines by using sed, a stream editor, to print only the parts you want (the \ at the end of the first two lines allows you to continue a line if the command gets too long):
wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O - | \ grep "[0-9][0-9]*:[0-9][0-9]*:[0-9][0-9]*" | \ sed 's/.*>\(.*\)<br><\/font>/\1/'
This prints out two lines, and the first one is the one you want, so use head to print only the first line (using the -n 1 switch):
wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O - | \ grep "[0-9][0-9]*:[0-9][0-9]*:[0-9][0-9]*" | \ sed 's/.*>\(.*\)<br><\/font>/\1/' | \ head -n 1
Now you can see that the title of the song is after the comma, so only print out what is after the comma and that following space:
wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O - | \ grep "[0-9][0-9]*:[0-9][0-9]*:[0-9][0-9]*" | \ sed 's/.*>\(.*\)<br><\/font>/\1/' | \ head -n 1| \ sed 's/.*, \(.*\)/\1/'
And there is the title of the current song. A bash script could take the above code and set a variable to its value:
Code Sample | #!/bin/bash
SONGTITLE=`wget http://wktz.jones.edu/wktz/BSI_WKTZFM_Page.htm -O - | \ grep "[0-9][0-9]*:[0-9][0-9]*:[0-9][0-9]*" | \ sed 's/.*>\(.*\)<br><\/font>/\1/' | \ head -n 1| \ sed 's/.*, \(.*\)/\1/'`
echo "The current song is $SONGTITLE" |
|