分页: 1 / 3
天气查询.pl
发表于 : 2010-01-21 10:11
由 eexpress
Re: 天气查询.pl
发表于 : 2010-01-21 10:37
由 ibear
为什么是32 26 40 19 15
准备翻译成python,perl太鸟语了

Re: 天气查询.pl
发表于 : 2010-01-21 10:53
由 eexpress
图片名,就这样啊。我懒得改。lol
Re: 天气查询.pl
发表于 : 2010-01-21 10:54
由 eexpress
如果你实现相同的功能,欢迎用各种脚本。只是估计,没更简洁的写法了。
Re: 天气查询.pl
发表于 : 2010-01-21 11:24
由 ibear
想起以前一个python笑话
Q:如何取得一个随机序列
A:请读入一个perl脚本
阿姨别见怪

Re: 天气查询.pl
发表于 : 2010-01-21 11:42
由 HuntXu
代码: 全选
#!/usr/bin/perl -w
use strict;
if ( !defined( $ARGV[0] ) ) {
print "Usage: weather.pl cityname\n";
exit 1;
}
my $curlcmd = "curl --connect-timeout 5 -s -S";
my $response =
`$curlcmd -d cityinfo=$ARGV[0] http://search.weather.com.cn/static/url2.php`;
exit 2 if ($?);
$response =~ m[(\d{9})];
if ( $1 == "999999999" ) {
print "no such a city.\n";
exit;
}
$response = `$curlcmd http://www.weather.com.cn/html/weather_en/$1.shtml`;
exit 2 if ($?);
my $weather = "Today is ";
$response =~
m[<dt style="float:left; width:300px;">Welcome! (.+) </dt>];
$weather .= "<$1>*";
$response =~ m[<title>(\S+)];
$weather .= " <$1>*";
@_ = ( $response =~ m[<div class="fut_weatherbox">.*?</div>]sg );
if ( @_ < 3 ) {
print "No forecast available.\n";
exit;
}
my %match;
for ( 1 .. 3 ) {
$_ = shift @_;
m{<h3>(?<date>.+?)</h3>.*?<h4[^>]+?>(?<weather>.+)</h4>.*?<h4.+High:(?<hightemp>[^<]+)</h4>.*?<h4.+Low:(?<lowtemp>[^>]+)</h4>}s;
%match = %+;
$match{weather} =~ s[<br/>][]g;
$weather .=
" $match{date}: $match{weather}, $match{lowtemp} ~ $match{hightemp}*";
}
printf "%s\n", $weather;
贡献一个吧...3天的天气查询,支持城市名拼音、英文和区号的...
Re: 天气查询.pl
发表于 : 2010-01-21 11:44
由 eexpress
额。没懂。难道是某FAQ乱翻译的?
胡须,你这啥。这么长。
Re: 天气查询.pl
发表于 : 2010-01-21 11:52
由 missing
好啊,有人来踢馆啦*^o^*
Re: 天气查询.pl
发表于 : 2010-01-21 11:53
由 xiooli
代码: 全选
#!/bin/bash
city="$1"; i=0
weather=("晴" "阴" "雨" "雾" "雪" "多云")
icons=("32" "26" "40" "19" "15" "26")
if [ "$city" ]; then
AGENT="User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7) Gecko/2009030814 Iceweasel/3.0.9 (Debian-3.0.91)"
url="http://www.google.cn/search?q=tq%20${city}"
weather_text="$(wget --user-agent="$AGENT" -q "$url" -O - \
| sed 's|alt=|<>|g;s|title=|<|g;s|</nobr>| |g;s|<[^>]*>||g;s|北京市专业气象台|\n|;s|今日.*|\n&|;s|°C||' \
| grep "°C")"
if [ "$weather_text" ]; then
weather_today="`echo $weather_text|awk -F'"' '{print $2}'`"
while [ "$i" -lt ${#weather[@]} ]; do
[ "`echo $weather_today|grep ${weather[$i]}`" ] && icon="${icons[$i]}" && break
((i++))
done
notify-send -u critical -i "./icons/$icon.png" "$city" "`echo "$weather_text" | tr '"' ' ' | sed 's| | |g;s|°C |&\n|g'`"
else
notify-send -u critical "未能获取天气"
fi
fi
Re: 天气查询.pl
发表于 : 2010-01-21 11:53
由 photor
Re: 天气查询.pl
发表于 : 2010-01-21 12:07
由 xiooli
perl 就像草书阿,呵呵
张丞相好书而不工。当时流辈皆讥笑之。丞相自若也。一日得句,索笔疾书,满纸龙蛇飞动。使侄录之。当波险处,侄罔然而止。执所书问曰:"此何字也?"丞相熟视久之,亦不自识。诟其侄曰:"汝胡不早问,致余忘之。"

Re: 天气查询.pl
发表于 : 2010-01-21 12:18
由 eexpress
xiooli, 那是你没入门。bash于我,是往事了哦。
pl的思路很清晰的。特殊变量晦涩而已。
支持你用bash去复制一个mocp-lrc.pl。论坛搜索吧。

Re: 天气查询.pl
发表于 : 2010-01-21 12:32
由 xiooli
eexpress 写了:xiooli, 那是你没入门。bash于我,是往事了哦。
pl的思路很清晰的。特殊变量晦涩而已。
支持你用bash去复制一个mocp-lrc.pl。论坛搜索吧。

我只是小点的玩意用 bash 而已,说起思路清晰可读性好,我认为还是 python 合适些。
Re: 天气查询.pl
发表于 : 2010-01-21 12:37
由 eexpress
支持。那你py来复制下功能啊。我比较下。包括那mocp的脚本
Re: 天气查询.pl
发表于 : 2010-01-21 13:06
由 daf3707
bash的脚本+EE的图标
perl没整出来
菜
notify-send -u critical -i "./icons/$icon.png"
这文件名加了“倒不显示图片了,不加却可以显示。