View Single Post
No!No!No!Yes!'s Avatar
Posts: 700 | Thanked: 846 times | Joined on Nov 2009
#12
Originally Posted by No!No!No!Yes! View Post

Before using this Beecon make sure you have "wget" package installed:

Start X-Terminal and type:
Code:
Nokia-N900-51-1:/home/user/MyDocs# wget
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.
Nokia-N900-51-1:/home/user/MyDocs#
If you don't the above output you need to install the package:
Code:
apt-get install wget
I quote a previous post to clarify some possible issues with respect to the use of wget to retreive webpages to be parsed for relevant contents.

Proxy support in N900 Maemo (don't know for previous versions) is far from being perfect and comfortable to handle.

While testing the previous Beecon behind our company's firewall, hildon-home/desktop got frozen because of the wget command trying to access internet resources while being blocked by our firewall.

Only way to unfreeze it was to kill both the shell script spawned by Beecon, awk and wget hung processes.

UPDATE 201002251730{Don't know why wget hung itself like this in endless timeout but} Setting -t 1 -T 3 options prevents wget from hanging and getting stuck for more then -T 3 seconds even if connection or proxy problems arise!!! However set -T <secs> according to the foreseen size of the web content to be fetched
I figured out a way to programmatically retrieve the proxy settings both for HTTP and for HTTPS from the internal MicroB browser configuration file: /home/user/.mozilla/microb/prefs.js

File holds several values related to proxy settings:
Code:
user_pref("network.proxy.http", "my.proxy.pri");
user_pref("network.proxy.http_port", 3128);
user_pref("network.proxy.no_proxies_on", "");
user_pref("network.proxy.ssl", "my.proxy.pri");
user_pref("network.proxy.ssl_port", 3128);
user_pref("network.proxy.type", 1);
These values are also updated every time a new internet/network connection is estabilished with the configurations present in the internet connection settings.


In order for wget to properly work behind a proxy, two environment variables must be set in this way:
Code:
export http_proxy=http://my.proxy.pri:3128/
export https_proxy=http://my.proxy.pri:3128/
Following one-liner script, which must be prepended to the wget command, does exactly that. It parses the MicroB/Browser configuration file and generates the statements to dynamically set those two variables:

Code:
`awk 'BEGIN {FS="[\(\", ;\)]+"}/proxy\.http"/{hx=$3}/proxy\.http_port"/{hp=$3}/proxy\.type"/{pt=$3}/proxy\.ssl"/{sx=$3}/proxy\.ssl_port"/{sp=$3}END{if(pt==0)exit;print "export http_proxy=http://" hx ":" hp "\/ export https_proxy=http://" sx ":" sp "\/"}' /home/user/.mozilla/microb/prefs.js`
So the final statement to feed the MLB Beecon with, will be this one:
Code:
`awk 'BEGIN {FS="[\(\", ;\)]+"}/proxy\.http"/{hx=$3}/proxy\.http_port"/{hp=$3}/proxy\.type"/{pt=$3}/proxy\.ssl"/{sx=$3}/proxy\.ssl_port"/{sp=$3}END{if(pt==0)exit;print "export http_proxy=http://" hx ":" hp "\/ export https_proxy=http://" sx ":" sp "\/"}' /home/user/.mozilla/microb/prefs.js`;wget -t 1 -T 3 -O - http://m.mlb.com/scores/`date +%Y%m%d`/ | awk 'BEGIN{t="NYY";m=0}/<td>.+<\/td>/{split(gensub(/<[^>]*>/,"","g"),a);if(a[1]!=t && a[3]!=t && a[4]!=t)next;m=1;if(a[2]=="vs."){print a[1] "\n" a[3] "\n" a[4],a[5];exit 1}print a[1],a[2] "\n" a[4],a[5] "\n" a[6];if((a[4]==t&&a[5]>a[2])||(a[1]==t&&a[2]>a[5]))exit 0;if(a[5]==a[2])exit 1;else exit 2}END{if(m==0){print "No\nMatch!\n";exit 1}}'
Of course you can save the proxy variables builder command into a file system shell script, lets say: pxy.sh and drop it into some PATH-reachable directory ex. /usr/sbin
Code:
# cat /usr/sbin/pxy.sh

awk '
BEGIN {
   FS="[\(\", ;\)]+"
}

/proxy\.http"/ { hx=$3 }
/proxy\.http_port"/ { hp=$3 }
/proxy\.type"/ { pt=$3 }
/proxy\.ssl"/ { sx=$3 }
/proxy\.ssl_port"/ { sp=$3 }

END {
   if ( pt==0 ) exit;
   print "export http_proxy=http://" hx ":" hp "\/ export https_proxy=http://" sx ":" sp "\/"
} ' /home/user/.mozilla/microb/prefs.js

#
Change permissions to executable:
Code:
chmod 755 /usr/sbin/pxy.sh
and, inside the Beecon, use a shorter statement prepended to wget command:
Code:
`pxy.sh` ; wget -t 1 -T 3 -O - http://m.mlb.com/scores/`date +%Y%m%d`/ | awk 'BEGIN{t="NYY";m=0}/<td>.+<\/td>/{split(gensub(/<[^>]*>/,"","g"),a);if(a[1]!=t && a[3]!=t && a[4]!=t)next;m=1;if(a[2]=="vs."){print a[1] "\n" a[3] "\n" a[4],a[5];exit 1}print a[1],a[2] "\n" a[4],a[5] "\n" a[6];if((a[4]==t&&a[5]>a[2])||(a[1]==t&&a[2]>a[5]))exit 0;if(a[5]==a[2])exit 1;else exit 2}END{if(m==0){print "No\nMatch!\n";exit 1}}'

Last edited by No!No!No!Yes!; 2010-02-25 at 19:28.
 

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