Active Topics

 



Notices


Reply
Thread Tools
Posts: 67 | Thanked: 36 times | Joined on May 2010 @ Claremont (LA), California
#151
So MLBeeCon is truly wonderful; thanks, No!No!No!Yes!

But I follow more than one team. And of course some people care about seeing certain teams lose, e.g. during a pennant race. So here's a somewhat fancier script. Drop it someplace convenient (I put it in /home/user/bin) and make it executable (chmod +x script-name). Then invoke it as:

/home/user/bin/mlbeecon CWS CWC -STL

which says you want to cheer for the White Sox, the Cubs, and whoever is playing Saint Louis.

The icon smiles if more of your teams win than lose, frowns if losers outnumber winners, and is smug if everything is balanced.

Code:
#!/bin/bash
#
# Fetch MLB scores and colorize them for use with Queen BeeCon.
#
USAGE='Usage: mlbeecon [team] [team] [-team] ...'
#
# Each team is an abbreviation used on the m.mlb.com site.  A team preceded
# by a minus sign is a "team you love to hate;" the icon becomes happy if
# that team loses.  The icon is happy if more teams win than lose, angry
# if losing dominates, and smug if the losers equal the winners.  (Ties
# aren't considered in this calculation.)

# Since ESPN thinks the world runs on Eastern time, use that for the
# date/time display at the top.  That makes it easier to read the
# schedule.  Change this field to $TZ if you prefer using your own
# timezone.
DISPLAYZONE=US/Eastern
#DISPLAYZONE=$TZ

# When we fetch the scores, we use a time zone a few hours to the
# west; this ensures that games that are in progress after midnight
# EST will still be shown; the next day's schedule won't come up until
# about 6 AM EST.
GRABZONE=US/Hawaii

echo "<span foreground=\"green\"><big><i>[`TZ=$DISPLAYZONE date '+%m/%d/%Y %H:%M'`]</i></big></span>"
wget -t 1 -T 10 -q -O - http://m.mlb.com/scores/`TZ=$GRABZONE date +%Y%m%d`/ \
  | awk 'BEGIN \
	{
	ntm = split("'"$*"'", tm)
	w = 0
	l = 0
	t = 0
	inScoreboard = 0
	inGame = 0
	}
    /<div.*id="scoreboard_module".*>/ \
	{
	inScoreboard = 1
	next
	}
    /<a href/  &&  inScoreboard \
	{
	split($0, linkLine, ">")
	inGame = 1
	next
	}
    /<\/div/  &&  inScoreboard \
	{
	inScoreboard = 0
	inGame = 0
	next
	}
    inGame \
	{
	if ($1 == "-"  ||  $1 == "vs.")
	    {
	    vsLine = $1
	    next
	    }
	inGame = 0
	split(linkLine[2], visitor)
	home = $1
	ist = 0
	for (i = 1;  i <= ntm;  i++)
	    {
	    ct = tm[i]
	    bad = 0
	    if (ct ~ /^-/)
		{
		bad = 1
		ct = substr(ct, 2)
		}
	    if (visitor[1] == ct  ||  home == ct)
		{
		ist = 1
		break
		}
	    }
        if (!ist)
	    {
	    print linkLine[2], vsLine, $0
	    next
	    }
	print "<span foreground=\"cyan\"><b><big>" linkLine[2], \
	  vsLine, $0 "</big></b></span>"
	if (vsLine == "vs."  ||  visitor[2] == $2)
	    t++
	else if ((visitor[1] == ct  &&  visitor[2] > $2) \
	  ||  ($1 == ct  &&  $2 > visitor[2]))
	    {
	    w += !bad
	    l += bad
	    }
	else
	    {
	    w += bad
	    l += !bad
	    }
	}
    END \
	{
	if (w + l + t == 0)
	    {
	    print "No\nMatch!\n"
	    exit 1
	    }
	else if (w > l)
	    exit 0
	else if (w < l)
	    exit 2
	else
	    exit 1
	}'
exit

# Old code
wget -t 1 -T 10 -q -O - http://m.mlb.com/scores/`TZ=$GRABZONE date +%Y%m%d`/ \
  | awk 'BEGIN \
	{
	ntm = split("'"$*"'", tm)
	w = 0
	l = 0
	t = 0
	}
    /<td>.+<\/td>/ \
	{
        s = gensub(/<[^>]*>/, "", "g")
        s = gensub(/[\t ]+/, " ", "g", s)
        split(s, a)
	ist = 0
	for (i = 1;  i <= ntm;  i++)
	    {
	    ct = tm[i]
	    bad = 0
	    if (ct ~ /^-/)
		{
		bad = 1
		ct = substr(ct, 2)
		}
	    if (a[1] == ct  ||  a[3] == ct  ||  a[4] == ct)
		{
		ist = 1
		break
		}
	    }
        if (!ist)
	    {
	    print s
	    next
	    }
	print "<span foreground=\"cyan\"><b><big>" s "</big></b></span>"
	if (a[2] == "vs."  ||  a[5] == a[2])
	    t++
	else if ((a[4] == ct  &&  a[5] > a[2]) \
	  ||  (a[1] == ct  &&  a[2] > a[5]))
	    {
	    w += !bad
	    l += bad
	    }
	else
	    {
	    w += bad
	    l += !bad
	    }
	}
    END \
	{
	if (w + l + t == 0)
	    {
	    print "No\nMatch!\n"
	    exit 1
	    }
	else if (w > l)
	    exit 0
	else if (w < l)
	    exit 2
	else
	    exit 1
	}'
EDIT 19-Aug-2010: one of the problems with screen scraping is that it breaks when the Web site changes its layout. ESPN just did that; this edit contains a rewritten version that works with the new ESPN site design.

Last edited by gkuenning; 2010-08-19 at 05:04. Reason: Fix bug in counting hostile teams
 
Posts: 527 | Thanked: 121 times | Joined on Feb 2010
#152
Originally Posted by No!No!No!Yes! View Post
While proper backup/restore developments are in the brewery you can have a look HERE
That made sense!

Cheers
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#153
Originally Posted by gkuenning View Post
So MLBeeCon is truly wonderful; thanks, No!No!No!Yes!

But I follow more than one team. And of course some people care about seeing certain teams lose, e.g. during a pennant race. So here's a somewhat fancier script. Drop it someplace convenient (I put it in /home/user/bin) and make it executable (chmod +x script-name). Then invoke it as:

/home/user/bin/mlbeecon CWS CWC -STL

which says you want to cheer for the White Sox, the Cubs, and whoever is playing Saint Louis.

The icon smiles if more of your teams win than lose, frowns if losers outnumber winners, and is smug if everything is balanced.

Code:
#!/bin/bash
#
# Fetch MLB scores and colorize them for use with Queen BeeCon.
#
USAGE='Usage: mlbeecon [team] [team] [-team] ...'
#
# Each team is an abbreviation used on the m.mlb.com site.  A team preceded
# by a minus sign is a "team you love to hate;" the icon becomes happy if
# that team loses.  The icon is happy if more teams win than lose, angry
# if losing dominates, and smug if the losers equal the winners.  (Ties
# aren't considered in thois calculation.)

echo "<span foreground=\"green\"><big><i>[`date '+%m/%d/%Y %H:%M'`]</i></big></span>"
wget -t 1 -T 10 -q -O - http://m.mlb.com/scores/`date +%Y%m%d`/ \
  | awk 'BEGIN \
	{
	ntm = split("'"$*"'", tm)
	w = 0
	l = 0
	t = 0
	}
    /<td>.+<\/td>/ \
	{
        s = gensub(/<[^>]*>/, "", "g")
        s = gensub(/[\t ]+/, " ", "g", s)
        split(s, a)
	ist = 0
	for (i = 1;  i <= ntm;  i++)
	    {
	    ct = tm[i]
	    bad = 0
	    if (ct ~ /^-/)
		{
		bad = 1
		ct = substr(ct, 2)
		}
	    if (a[1] == ct  ||  a[3] == ct  ||  a[4] == ct)
		{
		ist = 1
		break
		}
	    }
        if (!ist)
	    {
	    print s
	    next
	    }
	print "<span foreground=\"cyan\"><b><big>" s "</big></b></span>"
	if (a[2] == "vs."  ||  a[5] == a[2])
	    t++
	else if ((a[4] == tm[i]  &&  a[5] > a[2]) \
	  ||  (a[1] == tm[i]  &&  a[2] > a[5]))
	    {
	    w += !bad
	    l += bad
	    }
	else
	    {
	    w += bad
	    l += !bad
	    }
	}
    END \
	{
	if (w + l + t == 0)
	    {
	    print "No\nMatch!\n"
	    exit 1
	    }
	else if (w > l)
	    exit 0
	else if (w < l)
	    exit 2
	else
	    exit 1
	}'
YOU ARE COMMUNITY!!! MAN!

I've stuck your contribution to relevant section of the WIKI ... feel free to amend it at your convenience!!!
__________________
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
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#154
Originally Posted by gkuenning View Post
My widgets aren't auto-updating. I removed .queen_beecon, restarted the desktop, and recreated the MLB example (see following post for some improvements). It works fine when I click it, but doesn't update every 5 minutes. I did double-check the settings, and it's set correctly. Grepping .queen_beecon shows delayIndex=3.

Any thoughts as to why the timers aren't firing? If it's relevant, it was working earlier and then stopped; the clean restart was an attempt to get it to work properly.
Uhm... have you upgraded any QBW release lately?
__________________
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
 
Posts: 67 | Thanked: 36 times | Joined on May 2010 @ Claremont (LA), California
#155
Originally Posted by No!No!No!Yes! View Post
Uhm... have you upgraded any QBW release lately?
First, thanks for posting my script. I forgot to mention that I'd appreciate you doing that.

Based on timestamps in /var/lib/dpkg/info, it looks like I did an update about two days ago, at 08:55 Zulu on 2010-May-20. But the md5sums are from Mar 16, which I find odd. Surely you've done a release since then? How do I find out the version I'm running?
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#156
Originally Posted by Lake View Post
Hi - please is it possible to alter the script to point the snippet to here:

http://m.flickr.com/#/explore/interesting/

Think the other page is static - my fault, sorry!
There you go ...
__________________
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
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#157
Originally Posted by gkuenning View Post
First, thanks for posting my script. I forgot to mention that I'd appreciate you doing that.

Based on timestamps in /var/lib/dpkg/info, it looks like I did an update about two days ago, at 08:55 Zulu on 2010-May-20. But the md5sums are from Mar 16, which I find odd. Surely you've done a release since then? How do I find out the version I'm running?
Application Manager -> Uninstall ... Look in that list.
__________________
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
 
Posts: 76 | Thanked: 4 times | Joined on Apr 2010
#158
Originally Posted by No!No!No!Yes! View Post
There you go ...
FABULOUS!!!! Just so much better than the Ovi Store offering!

Now I just need to get the Ebay one working ok - any ideas? ;-)

Ps do you have a donate button or something?
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#159
For people with TIMER issues ... could you please provide QBW Release you are using and any other info you believe pertinent like for example:
  • It was working and now it doesn't
  • I did this and that and now is not working
  • I installed <xxx>, <yyy>, ... and now ...
  • ...
__________________
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
 
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#160
Originally Posted by Lake View Post
Now I just need to get the Ebay one working ok - any ideas? ;-)
Please elaborate further...

Originally Posted by Lake
I seem to be having a bit of a problem getting the Ebay Snippet to work correctly. I followed your instructions (very clear - many thanks) but I cannot seem to get a correct output, i.e. I edit the ebay item number and click "Save and Run" and I get the item title and picture, but no timer.
Is it just a timer issue you have here? What kind of output do you get?

Originally Posted by Lake
Having read your recent message about the Flickr snippet I installed "Wget" application but this doesn;t appear to have done the trick.
wget is not supposed to cause timer issues...anything else to report here?

Originally Posted by Lake
What might be useful is a suggested 'default' for layout, font etc to optimise the appearance of the widget maybe?
Please elaborate further...

Originally Posted by Lake View Post
Ps do you have a donate button or something?
Uhm ... well ... don't ask twice!!!!
__________________
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
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 05:15.