Jan'uary » 日志 » Torsmo [II]
Torsmo [II]
Jan 发表于 2005-03-12 10:21:09
下面是我用来看天气预报的脚本, 改自Gentoo Forums [http://forums.gentoo.org] 上的
同名脚本 ;p
~/.torsmo/forecast.sh
#!/bin/bash
# forecast.sh
# Run this in your /etc/crontab
# FIND YOUR LOCID
# ---------------
# First go to: http://xoap.weather.com/search/search?where=XXXXX
# The "XXXXX" can be anything you are searching for, such as zip code, city,
state, or country.
# After loading that web page up you should have a search returned with a "loc
id".
# The "loc id" will be used for your # weather.
DAYS="4"
LOCID="CHXX0044"
PARTNERID="1003666583"
LICENSEKEY="4128909340a9b2fc"
XMLFEED="http://xoap.weather.com/weather/local/"
XMLFILE="$XMLFEED$LOCID?dayf=$DAYS&prod=xoap&par=$PARTNERID&key=$LICENSEKEY&ut=C
"
LOCALXMLFILE="/home/XXX/.torsmo/forecast.xml"
wget -N $XMLFILE -O $LOCALXMLFILE
#I add this loop since the net condition isn't very well in ZJU
until [ -s $LOCALXMLFILE ]
do
wget -N $XMLFILE -O $LOCALXMLFILE
done
~/.forecast.pl:
#!/usr/bin/perl
## forecast.pl
use XML::Simple;
my $xmlfile = "/home/XXX/.torsmo/forecast.xml";
my $xml = XMLin($xmlfile);
my $numArgs = $#ARGV+1;
my $arg = $ARGV[0];
if ($numArgs == 1) {
if ($arg eq "updated") {
print $xml->{dayf}->{lsup} . "\n";
}
else {
print $xml->{loc}->{$arg} . "\n";
}
exit;
}
elsif ($numArgs == 2) {
my $day = $ARGV[0];
my $info = $ARGV[1];
if ($info eq "condday") {
print $xml->{dayf}->{day}->[$day]->{part}->[0]->{t} . "\n";
}
elsif ($info eq "condnight") {
print $xml->{dayf}->{day}->[$day]->{part}->[1]->{t} . "\n";
}
else {
print $xml->{dayf}->{day}->[$day]->{$info} . "\n";
}
else {
print $xml->{dayf}->{day}->[$day]->{$info} . "\n";
}
}
XML:Simple是一个简单的XML Parser, Gentoo上有ebuild, 其它发行版的用户可以上CPAN
上找到.
同名脚本 ;p
~/.torsmo/forecast.sh
#!/bin/bash
# forecast.sh
# Run this in your /etc/crontab
# FIND YOUR LOCID
# ---------------
# First go to: http://xoap.weather.com/search/search?where=XXXXX
# The "XXXXX" can be anything you are searching for, such as zip code, city,
state, or country.
# After loading that web page up you should have a search returned with a "loc
id".
# The "loc id" will be used for your # weather.
DAYS="4"
LOCID="CHXX0044"
PARTNERID="1003666583"
LICENSEKEY="4128909340a9b2fc"
XMLFEED="http://xoap.weather.com/weather/local/"
XMLFILE="$XMLFEED$LOCID?dayf=$DAYS&prod=xoap&par=$PARTNERID&key=$LICENSEKEY&ut=C
"
LOCALXMLFILE="/home/XXX/.torsmo/forecast.xml"
wget -N $XMLFILE -O $LOCALXMLFILE
#I add this loop since the net condition isn't very well in ZJU
until [ -s $LOCALXMLFILE ]
do
wget -N $XMLFILE -O $LOCALXMLFILE
done
~/.forecast.pl:
#!/usr/bin/perl
## forecast.pl
use XML::Simple;
my $xmlfile = "/home/XXX/.torsmo/forecast.xml";
my $xml = XMLin($xmlfile);
my $numArgs = $#ARGV+1;
my $arg = $ARGV[0];
if ($numArgs == 1) {
if ($arg eq "updated") {
print $xml->{dayf}->{lsup} . "\n";
}
else {
print $xml->{loc}->{$arg} . "\n";
}
exit;
}
elsif ($numArgs == 2) {
my $day = $ARGV[0];
my $info = $ARGV[1];
if ($info eq "condday") {
print $xml->{dayf}->{day}->[$day]->{part}->[0]->{t} . "\n";
}
elsif ($info eq "condnight") {
print $xml->{dayf}->{day}->[$day]->{part}->[1]->{t} . "\n";
}
else {
print $xml->{dayf}->{day}->[$day]->{$info} . "\n";
}
else {
print $xml->{dayf}->{day}->[$day]->{$info} . "\n";
}
}
XML:Simple是一个简单的XML Parser, Gentoo上有ebuild, 其它发行版的用户可以上CPAN
上找到.
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
