View Single Post
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#1
For QBW >=1.0.52
This is just a study purpose Beecon. Make sure you have wget package installed
It contains several new/advanced technics:
  • information persistency
  • clickable hot-spots management
  • intra-widget communication
  • variable parameters substitution
  • awk programming
  • awk variables pull-in from the shell
  • awk variables push-back to the shell
  • shell script functions
  • Pango Markup Language
  • Web scraping
I'll not be able to maintain the script on a regular basis as much of my spare time drowns into QBW dev/test but I promise I'll try to answer every question. (Bear with some bugs or unhandled error conditions)

Now let's stop blabbing and back into the core!!!

Functional view:









Extract & Copy attached images and shell script (make it executable chmod 777 mlbeecon_reloaded.sh) to directory:
Code:
/home/user/.queen_beecon_dir
Import Beecon:
Code:
[queen-beecon-header]
version=1,000000
checksum=3018258
[queen-beecon-exported-instance]
widgetType=0
widgetVisible=1
operationalStatus=0
hideCanvas=true
hideClickCanvas=true
snippetBgRGB=0
snippetExtBgRGB=#000000000000
beecon_lt0_ImgZoom=0
beecon_lt0_BgRGB=2
beecon_lt0_ExtBgRGB=#bebebebebebe
beecon_lt0_ImgFilename=queen-beecon-syserr.png
beecon_eq0_ImgZoom=0
beecon_eq0_BgRGB=3
beecon_eq0_ExtBgRGB=#000000000000
beecon_eq0_ImgFilename=mlb_news.png
beecon_eq1_ImgZoom=0
beecon_eq1_BgRGB=4
beecon_eq1_ExtBgRGB=#000000000000
beecon_eq1_ImgFilename=mlb_scoreboard.png
beecon_ge2_ImgZoom=0
beecon_ge2_BgRGB=5
beecon_ge2_ExtBgRGB=#000000000000
beecon_ge2_ImgFilename=mlb_standings.png
beecon_idxge2_ImgZoom=0
beecon_idxge2_BgRGB=11
beecon_idxge2_ExtBgRGB=#0000ffffffff
beecon_idxge2_ImgFilename=queen-beecon-index.png
widWidth=372.84403669724776
widHeight=420
instanceTitle=MLBeecon Reloaded
instanceCmd=/home/user/.queen_beecon_dir/mlbeecon_reloaded.sh "$QBW_REMEMBER_ME" "$QBW_HOTSPOT_PRESS" "$QBW_ID"
rememberMe=1:AL:BOS-Red Sox|NYY-Yankees:20100913:20100914:20100915
cmdImgFilename=queen-beecon.png
cmdImgAngle=0
cmdImgZoom=0
cmdFgRGB=1
cmdExtFgRGB=#ffffffffffff
cmdTextAngle=0
cmdVisibilityPosition=0
cmdImgVisibilityPosition=0
cmdJustify=0
cmdExtFont=Nokia Sans bold italic 12
cmdFontName=3
cmdFontSize=12
resImgFilename=queen-beecon-resimg.png
resImgAngle=0
resImgZoom=0
resFgRGB=1
resExtFgRGB=#ffffffffffff
resTextAngle=0
resVisibilityPosition=1
resImgVisibilityPosition=9
resJustify=0
resExtFont=Tahoma bold 10
resFontName=2
resFontSize=12
progressAnimationFrames=4
progressAnimationTimer=4
progressAnimationPos=4
progressAnimationAtClickXY=true
progressAnimationBasename=queen-beecon-progress
updOnStartup=false
updOnClick=true
updOnDesktop=false
updOnSight=false
delayIndex=9
customIntervalSecs=300
updNeworkPolicy=0
updOnDBUS=0
updOnDBUSBus=0
updOnDBUSMatchRule=
Here's the same text of attached script (for reference purpose only):
Originally Posted by mlbeecon_reloaded.sh
Code:
#dt=`TZ=EST+24 date +%Y%m%d`
QBW_REMEMBER_ME="$1"
QBW_HOTSPOT_PRESS="$2";
QBW_ID="$3";
TAB=`echo "$QBW_REMEMBER_ME" | cut -f1 -d:`
LEAGUE=`echo "$QBW_REMEMBER_ME" | cut -f2 -d:`
FAVLONG=`echo "$QBW_REMEMBER_ME" | cut -f3 -d:`
PREVDATE=`echo "$QBW_REMEMBER_ME" | cut -f4 -d:`
DISPLAYDATE=`echo "$QBW_REMEMBER_ME" | cut -f5 -d:`
NEXTDATE=`echo "$QBW_REMEMBER_ME" | cut -f6 -d:`

remember_me()
{
        run-standalone.sh dbus-send --session --type=method_call --dest=oh.no.more.qbw /oh/no/more/qbw$QBW_ID oh.no.more.qbw.set_param_string string:"rememberMe" string:"$TAB:$LEAGUE:$FAVLONG:$PREVDATE:$DISPLAYDATE:$NEXTDATE" string:"";
}

#echo $TAB
#echo $LEAGUE
#echo $FAVLONG
#echo $PREVDATE
#echo $DISPLAYDATE
#echo $NEXTDATE


if [ "_$PREVDATE" == "_" -o $DISPLAYDATE == "_" -o "_$NEXTDATE" == "_" ]; then 
    DISPLAYDATE=`TZ=EST+05EDT date +%Y%m%d`
    PREVDATE=`TZ=EST+29 date +%Y%m%d`
    NEXTDATE=`TZ=EST-19 date +%Y%m%d`
fi

case $QBW_HOTSPOT_PRESS in
[123])
    DISPLAYDATE=`TZ=EST+05EDT date +%Y%m%d`
    if [ "$QBW_HOTSPOT_PRESS" -ne "$TAB" ]; then
        remember_me
    fi
    TAB=$QBW_HOTSPOT_PRESS;
    ;;
esac

case $TAB in
1)
    wget -U " " -t 1 -T 10 -q -O - "http://m.espn.go.com/mlb/news?lang=EN" | awk -v fav="$FAVLONG" -v hi="yellow" -v oc='white' -v ec='gray' -- '
BEGIN {
    FS="";
    infoOk=0
}

/^<\/style>.+<\/html>/ {
    print "\n\n<span foreground=\"cyan\" font=\"bold 15\"></span>";
    x=split($0,m,"(<div class=\"ind[^\"]*\"[^>]*><a  class=\"inline\"[^>]*>)|(</a> </div>)");
    for (i=2;i<x-1;i++) {
        infoOk=1
        if (n%2==0)
            c=oc;
        else
            c=ec;
        gsub(/(<[^>]*>)+/,"",m[i]);
        if (m[i]!="") {
            n++;
                    t=split(fav,fa,"[\|\-]");
                    for(f=1;f<=t;f++) {
#                print f "-" fa[f] "-" m[i]
                if (match(m[i],fa[f])) c=hi;
            }
            print "<b><span foreground=\""c"\">- "m[i]"</span></b>";
        }
    }
}

END {
        if (infoOk==0) print "<span foreground=\"red\" font=\"bold 17\">\n\n No Info Available</span>";
}'
    remember_me
    exit 0
    ;;
 2)
    case $QBW_HOTSPOT_PRESS in
    [47])
        DISPLAYDATE=$PREVDATE
        ;;
    [69])
        DISPLAYDATE=$NEXTDATE
        ;;
    esac
    wget -U " " -t 1 -T 10 -q -O - "http://m.espn.go.com/mlb/scoreboard?date=$DISPLAYDATE&lang=EN" | awk -v fav="$FAVLONG" -v hi="yellow" -v oc='white' -v ec='gray' -- '
BEGIN {
    FS="";
    infoOk=0
}

/^<\/style>.+<\/html>/ {
    print "<span font=\"bold 6\">\n\n\n</span>";
    match($0,/<\/a> \| [A-Z0-9 ]+/);
    print "<tt><span foreground=\"cyan\" font=\"bold 12\"> "substr($0,RSTART+7,6)"</span></tt>";
    match($0,/scoreboard\?date=[0-9]+/);
    pd=substr($0,RSTART+16,8)
    match($0,/ <a  href=\"scoreboard\?date=[0-9]+/);
    nd=substr($0,RSTART+27,8)
    print "PREVDATE"pd
    print "NEXTDATE"nd
    match($0,"> [\|] [^\|]+");
    x=split($0,m,"(<div id=\"game[^>]*><div class=\"ind[^>]*><a  href=\"/mlb/gamecast[^>]*>)|(</a></div></div>)");
    for(i=2;i<x;i++) {
        infoOk=1;
        if (n%2==0)
            c=oc;
        else
            c=ec;
        if (m[i]!="") {
            n++;
                    t=split(fav,fa,"[\|\-]");
                    for(f=1;f<=t;f+=2) {
#                print f "-" fa[f] "-" fa[f+1] "-" m[i]
                            if (match(m[i],fa[f])) c=hi;
            }
            split(m[i],p," ");
            if (p[2]=="at")
                printf "<tt><span font=\"bold 14\" foreground=\""c"\">      %3s @ %3s %s %s %s %s</span></tt>\n", p[1], p[3], p[4], p[5], p[6], p[7], p[8];
            else
                printf "<tt><span font=\"bold 14\" foreground=\""c"\">      %3s %2s-%-2s %3s %s %s %s</span></tt>\n", p[1], p[2], p[4], p[3], p[5], p[6], p[7];
        }
    }
}

END {
        if (infoOk==0) print "<span foreground=\"red\" font=\"bold 17\">\n\n No Info Available</span>";
}' | while read out
do
    if [ "`echo $out|cut -c1-8`" == "PREVDATE" ];then
        PREVDATE="`echo $out|cut -c9-16`"
    elif [ "`echo $out|cut -c1-8`" == "NEXTDATE" ];then
        NEXTDATE="`echo $out|cut -c9-16`"
        remember_me
    else echo "$out"    
    fi
done
    exit 1
    ;;
3)
    if [ "$LEAGUE" == "AL" ]; then
        LG=7
        LEAGUE="NL"
    elif [ "$LEAGUE" == "NL" ]; then
        LG=8
        LEAGUE="WC"
    elif [ "$LEAGUE" == "WC" ]; then
        LG=9
        LEAGUE="AL"
    fi

    wget -U " " -t 1 -T 10 -q -O - "http://m.espn.go.com/mlb/standings?groupId=$LG&lang=EN" | awk -v fav="$FAVLONG" -v hi="yellow" -v lg="$LG" -v oc='red' -v ec='gray' -- '
BEGIN {
    FS="";
    if (lg==9) st="\n Wildcards";
    infoOk=0;
    wcc=-1;
    fontsize=12;
    blanks="";
}

/^<\/style>.+<\/html>/ {
    print "\n\n<tt><span foreground=\"cyan\" font=\"bold 12\">"st"</span></tt>";
    match($0,"<table  class=\"table\".*</table>");
    q=substr($0, RSTART, RLENGTH);
    gsub(/(<[^>]*>)+/,"|",q);
    x=split(q,m,"\|");
    for(i=2;i<x;i+=5) {
        infoOk=1;
        if (m[i]=="AL EAST" || m[i]=="AL CENT" || m[i]=="AL WEST" || m[i]=="NL EAST" || m[i]=="NL CENT" || m[i]=="NL WEST" || m[i]=="AL" || m[i]=="NL") {
            wcc=0;            
            c=oc;
        } else {
            c=ec;
        }
                t=split(fav,fa,"[\|\-]");
                for(f=1;f<=t;f+=2) {
#            print f "-" fa[f] "-" fa[f+1] "-" m[i]
                        if (match(m[i],fa[f+1])) c=hi;
        }
        if (lg==9) {
            if (wcc>=0&&wcc<9) wcc++;
            else continue;
        };
        if ( match(m[i+1],/\([0-9]+\)/) ) {m[i+1]=m[i] substr(m[i+1],RSTART,RLENGTH);i++;}
        printf("<tt><span font=\"bold %d\" foreground=\"%s\"> %s%-15s %3s %3s %5s %5s</span></tt>\n", fontsize, c, blanks, m[i], m[i+1], m[i+2], m[i+3], m[i+4]);
    }
}

END {
        if (infoOk==0) print "<span foreground=\"red\" font=\"bold 17\">\n\n No Info Available</span>";
}'
    remember_me
    exit 2
    ;;
*)
    echo "UNKNOWN TAB $TAB"
    ;;
esac
Enjoy!
Attached Files
File Type: zip mlbeecon_reloaded-1.zip (166.9 KB, 191 views)
File Type: zip mlbeecon_reloaded-2.zip (329.8 KB, 163 views)
__________________
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-09-15 at 05:11.
 

The Following 3 Users Say Thank You to No!No!No!Yes! For This Useful Post: