一个天气预报的脚本

sh/bash/dash/ksh/zsh等Shell脚本
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

一个天气预报的脚本

#1

帖子 bones7456 » 2007-09-04 14:18

闲来无事,写了天气预报的脚本,与大家分享。
本人菜鸟,如有任何问题或建议,欢迎指正。谢谢。

数据来自 http://weather.265.com

20080524更新,感谢bthink发现265的改版消息。
附件
weather.tar
脚本
外加一个城市代码文件
(10 KiB) 已下载 258 次
上次由 bones7456 在 2008-05-24 19:14,总共编辑 3 次。
关注我的blog: ε==3
头像
vim7
帖子: 3
注册时间: 2007-09-04 13:48

#2

帖子 vim7 » 2007-09-04 14:31

tar.. - -!!
用什么写的? shell?
头像
ofewiofewo
帖子: 547
注册时间: 2007-06-02 14:56

#3

帖子 ofewiofewo » 2007-09-04 15:24

呵呵,学习,填了几个city参数

广州: 25℃~29℃ 下午:阴转多云,阵雨;晚上:阴转多云,小雨
漳州: 24℃~29℃ 下午:阴转多云,小阵雨;晚上:阴转多云,有雨
丹东: 17℃~28℃ 下午:晴转多云;晚上:晴转多云
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#4

帖子 bones7456 » 2007-09-04 16:03

vim7 写了:tar.. - -!!
用什么写的? shell?
就是shell。
ofewiofewo 写了:呵呵,学习,填了几个city参数

广州: 25℃~29℃ 下午:阴转多云,阵雨;晚上:阴转多云,小雨
漳州: 24℃~29℃ 下午:阴转多云,小阵雨;晚上:阴转多云,有雨
丹东: 17℃~28℃ 下午:晴转多云;晚上:晴转多云
:D :D :D 见笑了。
关注我的blog: ε==3
头像
zhan
帖子: 1880
注册时间: 2005-08-15 0:04
来自: 南7技校

#5

帖子 zhan » 2007-09-04 16:34

无聊的人又多了一个.

http://rafb.net/p/APZfJp42.html

代码: 全选

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, re, sys

def getcitycode():
        conn=urllib.urlopen("http://weather.265.com/get_weather.php?action=get_city")
        citysrc=conn.read().decode("gbk").encode("utf8")
        conn.close()
        citycode=re.findall('[0-9]{5}', citysrc)[0]
        return citycode

def getweather(code):
        url="http://weather.265.com/weather/"+code+".htm"
        conn=urllib.urlopen(url)
        weasrc=conn.read().decode("gbk").encode("utf8")
        conn.close()
        wea=re.findall('show_weather\("(.*)"\)', weasrc)[0].split("'")
        weather=[item  for item in wea if item !="," and ")" not in item and "(" not in item]
        city=wea[0].split('"')[0]
        option=[u'今天:',u'上午:',u'下午:',u'晚上:',u'明天:',u'上午:',u'下午:',u'晚上:']
        #print "\n".join(weather)
        index=0
        print u'城市:',city
        while index < (len(option)):
                print option[index],weather[index]
                index=index+1

if __name__=='__main__':
        try:
                code=sys.argv[1]
        except:
                code=getcitycode()
        getweather(code)
python 版的,比 bash 的好看点...
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#6

帖子 eexpress » 2007-09-04 16:43

py的库,比shell的多啊。 :lol:
● 鸣学
kyowu
帖子: 11
注册时间: 2007-03-25 14:08

#7

帖子 kyowu » 2007-09-04 19:24

是这样用么?
解压后,
chmod -x weather
./weather

为什么提示
bash: ./weather:Permission denied
???
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#8

帖子 BigSnake.NET » 2007-09-04 19:45

kyowu 写了:是这样用么?
解压后,
chmod -x weather
./weather

为什么提示
bash: ./weather:Permission denied
???

代码: 全选

chmod u+x weather
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
gregorian
帖子: 20
注册时间: 2007-04-02 15:04

#9

帖子 gregorian » 2007-09-04 22:42

chmod +x

建议多看看基础的命令,再来学shell
fireshort
帖子: 161
注册时间: 2007-03-08 19:12
联系:

#10

帖子 fireshort » 2007-09-05 13:10

用起来挺方便,不过265的数据是不是不太准确,好像跟121的相差比较大?
kyowu
帖子: 11
注册时间: 2007-03-25 14:08

#11

帖子 kyowu » 2007-09-05 15:28

grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'

这句话如何解析呀?
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#12

帖子 bones7456 » 2007-09-05 16:26

kyowu 写了:grep 'wid_265=' | sed -e 's/document\.cookie\ =\ "wid_265=//' | sed -e 's/".*//g'

这句话如何解析呀?
在文本中挑出有含有'wid_265='的那行,再剔除
document.cookie = "wid_265=

"后面的内容。
最终就只留下个数字了。
关注我的blog: ε==3
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#13

帖子 bones7456 » 2007-09-05 16:28

kyowu 写了:是这样用么?
解压后,
chmod -x weather
./weather

为什么提示
bash: ./weather:Permission denied
???
:shock: :shock: :shock: tar包解开了应该本来就有可执行权限吧,偏偏要把它给去掉~~~
关注我的blog: ε==3
kyowu
帖子: 11
注册时间: 2007-03-25 14:08

#14

帖子 kyowu » 2007-09-05 16:49

明白了
头像
Beetle
帖子: 1637
注册时间: 2005-10-14 16:55
系统: OS X
来自: 江苏
联系:

#15

帖子 Beetle » 2007-09-08 17:56

多个城市代码是用什么隔开?
回复