广告位招租 联系qq:165345322

自动获取天气预报,并用conky显示、用festival朗诵

时间:2007-02-23 13:32:17   来源:freebsdchina  作者:IOU  点击:次  出处:技术无忧
关键字:conky 系统 监视 工具

conky是一个非常强大的系统监视工具,可以在桌面上实时地显示你想要的内容,简直就是传说中的“月光宝盒”。你可以实时地看到CPU的使用情况,MPD的播放情况,或者当地的天气情况等等,是出门在外孤独难耐时必备的杀人工具。

我喜欢开机就听到今天的天气预报和需要做的事情,它们的内容也能biu地一下显示于桌面上,于是就有了下面的小玩意儿,请过往的朋友多提意见。先贴出来我的~/.conkyrc的TEXT部分(其他部分很简单,我的default_color设为DarkGray)。我要求conky每隔两小时报一下天气和提醒我做某些事情,如果不喜欢机器频繁打扰,也可以修改语音提示那几行命令,只要求在开机的时候提醒一下就可以了。天气预报的更新时间可以根据需要自己设定。

代码:

TEXT
${color green}System Status $color
  |
  +-- Uptime:${color white} $uptime $color
  +-- CPU Usage:${color #cc2222} $cpu% ${cpubar} $color
  +-- RAM Usage:${color white} $mem/$memmax - $memperc% $color
  +-- Adapter status:${color #cc2222} $apm_adapter $color
  +-- Battery life:${color white} $apm_battery_time - $apm_battery_life

${color green}Music Player Daemon $color
  |
  +-- MPD Status:${color white} $mpd_status $mpd_elapsed/$mpd_length $color
  +-- Artist:${color white} $mpd_artist - $mpd_title $color
  +-- Process:${color #88aadd} $mpd_percent% $mpd_bar $color
  +-- Volume:${color white} $mpd_vol

${color green}Beijing Weather of${execi 7200 ~/.conky/weather.sh Time} $color
  |
  +-- Sky:${execi 7200 ~/.conky/weather.sh Sky}
  +-- Temperature:${execi 7200 ~/.conky/weather.sh Temperature}
  +-- Wind:${execi 7200 ~/.conky/weather.sh Wind}
${execi 7200 festival --tts /tmp/weather.txt}
$color${pre_exec more /tmp/.remind}
${execi 7200 festival --tts /tmp/.remind}

 


这里的weather.sh是一个自动从http://weather.yahoo.com获取天气信息的脚本,存放在~/.conky/里。具体内容如下:
代码:

#!/usr/local/bin/bash
# Get weather information from Yahoo
# Modified by IOU
# Feb-10-2007
# The link is for the city of Beijing
link=CHXX0008.html
weather=/tmp/weather.txt
temporary=/tmp/temporary.txt
location=http://weather.yahoo.com/forecast/$link

lynx -accept_all_cookies -dump $location > $weather
begin=`cat -n $weather | grep "How to" | cut -d ' ' -f4`
end=`expr $begin + 2`

head -n $end $weather > $temporary
tail -n 2 $temporary > $weather
cat $weather | cut -d "*" -f2 > $weather
rm -f $temporary

case $1 in
Time)
    head -n 1 $weather | cut -d : -f1
    ;; 
Sky)
    head -n 1 $weather | cut -d : -f2 | cut -d . -f1
    ;; 
Temperature)
    head -n 1 $weather | cut -d . -f2
    ;; 
Wind)
    head -n 1 $weather | cut -d . -f3
    ;; 
*)
    exit
    ;; 
esac

 


我这里所选的城市是“Beijing”,也可以选其他的城市,不过link的内容就要随选择而定了。脚本可能有更高效的,或者更简化的,如果你搞出来了别忘了告诉我一哈。


有关festival的使用,以前我写过一个小小的帖子介绍,感兴趣的朋友可参考http://www.freebsdchina.org/forum/topic_31840.html&highlight=IOU

不知道如何上截图。我的这个conky比较简约但有又不失玉树临风。可以做得很花哨(http://conky.sourceforge.net/),但俺不太喜欢。

到此为止,Have fun!

想自己动手组装电脑吗?想了解市场行情吗?来技术无忧DIY资讯一切烦脑都没有!


文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

300x250广告位招租