View Single Post
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#2
Just a few words to be spent about the command driving the Widget's look and behaviour:

It is basically divided in 3 parts:
  1. First command basically outputs a colored and bigger date text (please refer to Pango Markup Language for e complete reference to Tags)
    Code:
    echo "<span foreground=\"green\"><big><i>[`date +%m/%d/%Y`]</i></big></span>";
  2. Second command is the fetch of the mobile version of the MLB Results webpage (bandwidth friendly )
    -t 1 try just one time and abort if unsuccessful
    -T 10 abort operation if not completed within 10 seconds
    -q be quiet and do not output any warning/error/operation message
    -O - print fetched page to standard output
    `date +%Y%m%d` will be substituted at runtime with the current date in the format <yyyymmdd> to identify the correct webpage to be fetched
    Code:
    wget -t 1 -T 10 -q -O - http://m.mlb.com/scores/`date +%Y%m%d`/
  3. Output of command 2 is then piped to this 'awk' script which will parse the output, identify winner/loser, highlight & format favourite Team's match and return the exit code which will drive the relevant icon/image display. Here's a better looking and slightly commented awk source code.
    In code, replace t="NYY" with t="your team here" (short form)
    Code:
    BEGIN {
    	t="NYY"; # Favourite Team!!!
    	m=0;
    }
    
    /<td>.+<\/td>/ { # We find every line of the table which displays results
    	s=gensub(/<[^>]*>/,"","g");   # We remove every simple HTML tag from 
    				      # out input
    
    	s=gensub(/[\t ]+/," ","g",s); # and replace every multiple instances
    				      # of TABs or SPACEs with just one SPACE
    
    	split(s,a); # We create an array of blank delimited fields
    		    # representing our teams name, score, "vs." string, 
    		    # situation "Final", "Top 5" ...
    
    	if(a[1]!=t && a[3]!=t && a[4]!=t) { # Test if our favourite team 
    
    		print s; 		    # just print with no special
    					    # Pango tag if other teams
    
    		next; 			    # and go parse next line
    	}
    
    	m=1; # Found favourite team... set flag accordingly
    
    	# Print our fav Team's match with Pango tags for cyan color, 
    	# bold & big size font
    	print "<span foreground=\"cyan\"><b><big>" s "</big></b></span>"; 
    
    	if(a[2]=="vs.") { # if second field is string "vs." and not a score
    			  # this means game has not started yet
    
    		ex=1; 	  # We will exit with just a neutral exit status
    		next; 	  # and go parse next line
    	}
    
    	if((a[4]==t&&a[5]>a[2])||(a[1]==t&&a[2]>a[5])) { # Checks is our fav
    							 # Team's winning!!!
    
    		ex=0; # Yes ... prepare exit with big smiley face exit status!
    		next; # and go parse next matches
    	}
    
    	if(a[5]==a[2]) { # Is this a still tie game??
    		ex=1; # Yes ... We will exit with just a neutral exit status
    		next; # and go parse next matches
    	} else {      # We have lost ... SAD news!!!
    		ex=2; # Prepare mourning exit status
    		next; # sadly process other teams
    	}
    }
    
    END { # these will be the very last statements performed
    	if(m==0) {		      # Have we found our fav team's match
    		print "No\nMatch!\n"; # No ... just output a No Match at the 
    				      # end of the list
    		exit 1;	 	      # and exit with neutral exit status
    	} else
    		exit ex; # we now return to beecon with defined exit status
    }
__________________
Have a look at Queen BeeCon Widget (WIKI) Customizable and flexible widget-based multi-instance monitoring, alerting and interactive tool for the N900
Please provide comments and feedback for having QBW supported and enhanced further - (DONATE) - v1.3.3devel / v1.3.3testing / v1.3.3extras

Last edited by No!No!No!Yes!; 2010-03-16 at 01:29.