FetionWeather: 利用 Crontab+Libfetion 预报天气

QReadBookZhuaShuShell 的作者 fangvv 今天给我们发来了他的新作 FetionWeather── 使用 Libfetion 发送天气预报到自己和飞信好友的移动手机上。

要求

Linux 机器,crontab,g++,Libfetion 0.9.2,Bash Shell,有效的飞信帐号,网络连接

步骤

  1. 在系统中创建 fetion 目录,假设前面的路径为 PATHTOFETION。
  2. 下载 linux_fetion_0.9.2.tar.gz 到 fetion 目录。
  3. 使用 tar 解压 linux_fetion_0.9.2.tar.gz 压缩包。
  4. 提取 FetionWeather.zip 中的 weather.cpp 和 getweather 到 fetion 目录。
  5. 注意修改 weather.cpp 中的 CHANGE_THIS_WITH_FETIONID 为你要发送的好友的数字 id,必须已经是飞信好友。
  6. 注意修改 Shell 脚本 getweather 中的预报 URL:可以从 http://wap.weather.com.cn/wap/search/ 查找你所在的城市 24 小时天气预报 URL。
  7. 编译:g++ weather.cpp linux_fetion_0.9.2/lib/libfetion_32.a -o weather -I"linux_fetion_0.9.2/" -lcurl -pthread
  8. 修改 getweather 运行权限 chmod 755 getweather
  9. 在 fetion 目录下测试一下运行情况:

    ./weather YOURID YOURPASSWORD "`./getweather`"
    
  10. 可以正常接收预报短信后,加入到 Crontab:

    0 19 * * * /PATHTOFETION/fetion/weather YOURID YOURPASSWORD "`/PATHTOFETION/fetion/getweather`"
    

(每晚 19 点时发送天气预报,因数据源 wap.weather.com.cn 每天 18:00 之后给出第二天天气预报,因此请该时刻之后再发送天气短信)

说明

主要短信发送函数为 fs_send_sms 和 fs_send_sms_to_self。0.9.3 版本的 libfetion 因使用起来有问题,因而现在我选择使用的是 0.9.2。自己用的小程序,注重功能,代码简陋,可以根据您的需要自己修改使用。该程序亦可用来循环发送垃圾内容给飞信好友,本人对此引发的后果概不负责。

下载 FetionWeather

Read More:

  • No related posts

28 Comments

  1. 1 venhow Commented @ 2009-04-27 17:33Reply to this comment

    这个貌似不错的。。

  2. 2 YCF.name Commented @ 2009-04-27 17:39Reply to this comment

    一直使用Google的天气预报 http://www.google.com/sms/alerts 免费省事。。。

  3. 3 zhuobing Commented @ 2009-04-27 17:46Reply to this comment

    嗯 不错的思路 可以在线使用下http://www.xiayu.info 呦~

  4. 4 Ready Commented @ 2009-04-27 17:53Reply to this comment

    每天都接受那些不痛不痒的天气预报,还不如仅仅接受下雨或者下雪的天气提醒比较轻松,“今天要带伞吗?” http://xiayu.info/ 同样利用了飞信来进行,不过它只在需要带伞的天气才发送提醒。

  5. 5 Iven Commented @ 2009-04-27 18:11Reply to this comment

    Google 天气用了一段,发现我根本不关心天气……

  6. 6 Ivan Chen(西滨) Commented @ 2009-04-27 18:12Reply to this comment

    我最经常收到的天气预报是“局部地区有分散短时阵雨”,你说我带伞还是不带伞好呢?

  7. 7 venhow Commented @ 2009-04-27 18:24Reply to this comment

    @Ivan Chen(西滨): 请带半把伞。。。

  8. 8 Iven Commented @ 2009-04-27 18:30Reply to this comment

    @Ivan Chen(西滨): 不用带,下雨再回来拿~

  9. 9 windwiny Commented @ 2009-04-27 18:43Reply to this comment

    下雨天请带雨具,晴天请带..

  10. 10 xiaket Commented @ 2009-04-27 19:00Reply to this comment

    嘿嘿,我做过完全一样的东西~

  11. 11 shuguang Commented @ 2009-04-28 4:25Reply to this comment

    还以为二楼说的那个网站可以用飞信接受天气预报呢... 结果还是要提供手机号码才行

  12. 12 dadianchi Commented @ 2009-04-28 8:13Reply to this comment

    我能说几句吗?

  13. 13 dadianchi Commented @ 2009-04-28 8:29Reply to this comment

    我多说两句,每天早上都会看linuxtoy的,她能给我一些我想要的资讯。一直都没说过什么。今天想说两句。关于利用 Crontab+Libfetion 发送天气,我最初看到这个程序是在一个牛人的个人博客上,而且功能要更强大。

    http://blog.solrex.cn/articles/diy-free-weather-forecast-sms.html

    那是很久以前了,是我在搜到《使用开源软件-自己动手写操作系统》的时候顺便看到的。就开始使用了,给自己和朋友发,挺好的,就是有时候登录不上去。

    看了fangvv 的程序,首先说明我没有冒犯的意思,只是想保护别人的原创。 weather.cpp 和 LibFetion作者邓东东的“Hello LibFetion demo”太像了,http://www.libfetion.cn/Docs-dve/hello-libfetion.c

    而且和solrex的相比是有差距的。

    fangvv 的创新在于是抓取的是wap网页,无用的信息少,用bash处理的时候更简单一些。

    不想制造是非,只是把一些问题说明白。

    over

  14. 14 tonn Commented @ 2009-04-28 10:11Reply to this comment

    用http://fetionapi.appspot.com/ 或者fetion的python脚本都比libfetion好啦 http://blog.lazytech.info/2008/11/05/python-fetion/

  15. 15 黑日白月 Commented @ 2009-04-28 10:41Reply to this comment

    @dadianchi: 没别的意思,fangvv 不是都说了是基于 LibFetion 的了么……

  16. 16 fangvv Commented @ 2009-04-28 11:58Reply to this comment

    我的时间和精力不多,这个程序仅仅是满足自己和家人的需要,基本的功能实现了,运行了很多天也挺正常的,觉得是一个有用的工具。至于solrex我很早就看了,他做的很好。说到创新,甚至连抓取wap我也是从其它一个网页里学到的,何来创新之有?我也看到有利用Libfetion实现邮件推送的google code上的fgmail,也挺好的,有需要可以去用。

    这个简陋的程序,仅仅是让Toy在这里公布出来给大家用而已,如果喜欢可以用,不喜欢可以不用,觉得不好可以自己去改,不存在和谁比的问题,也不是刻意去抄袭别人的创意和代码,实在是犯不着啊,呵呵。

  17. 17 dadianchi Commented @ 2009-04-28 12:13Reply to this comment

    是我多事了,抱歉

  18. 18 lookweather Commented @ 2009-04-28 12:17Reply to this comment

    可以使用 http://blog.solrex.cn/articles/diy-free-weather-forecast-sms.html 中的下载天气的python模块和 http://cocobear.info/blog/2008/12/31/pyfetion-release/ 提供的PyFetion模块,组合出一个纯python实现的天气短信发送,哦远离make了

  19. 19 trent Commented @ 2009-04-28 13:11Reply to this comment

    我看到fangvv写过看电子书的程序,刚好我也写过,顺便可以贴出来献献丑 :-)

    http://getfmx.googlecode.com/

    也是做着自己玩的东西,也没有指望能和谁比。我觉得大家可以不必管程序是不是抄袭,作者也未必是刻意隐瞒,仅仅忘了提到感谢原作者的话罢了。毕竟作者好心把程序贴出来给大家用,我们还是心存感激的比较好。不然谁还敢开发自由软件啊?

  20. 20 leon Commented @ 2009-04-28 15:05Reply to this comment

    感谢fangvv的程序,感谢solrex的程序. 不过提一点点,天气信息的抓取其实可以采用http://mobile.t7online.com/cgi-bin/city?L=cnwxxxx最后的xxxx替换成所在城市天气代码.这里的信息比weather.com.cn的好一些. 另外我发现t7ongline的城市代码和weather.com.cn的不太一致!!

  21. 21 Fwolf Commented @ 2009-04-28 23:33Reply to this comment

    我是自己用bash抓下来,整理后发送的, 主要还是libfetion好用啊。

  22. 22 uuwang Commented @ 2009-04-29 19:04Reply to this comment

    有人编译成功吗,我ld的时候说找不到-lcrul,不知道怎么回事。

  23. 23 fangvv Commented @ 2009-04-29 19:11Reply to this comment

    需要系统里安装有libcurl这个库curl.haxx.se上有介绍

  24. 24 Yeqin Su Commented @ 2009-05-01 16:16Reply to this comment

    So great

  25. 25 Yeqin Su Commented @ 2009-05-01 16:54Reply to this comment

    对了,0.9.3能用否?!

  26. 26 xiaket Commented @ 2009-05-02 9:31Reply to this comment

    @Yeqin Su:

    不能

  27. 27 fangvv Commented @ 2009-05-03 19:33Reply to this comment

    @Yeqin Su: 那个版本有问题,不能给自己发短信。

  28. 28 happipuppy Commented @ 2009-05-04 19:20Reply to this comment

    我一直在用solrex写的那个sendsms程序,赞一个! 我也是去 http://wap.weather.com.cn 抓的天气,发短信的脚本是用 Perl 写的,链接如下: http://blog.chinaunix.net/u3/93312/showart_1908632.html