python写vim script之 山寨版气象

说明:
1: http://www.hzqx.com/gzhfw/dqyb.asp是杭州气象网的短期预报页,页面简单,预报准确,童叟无期.....
2: 代码写得极其丑陋,不过可以工作 (fc6+gvim72)


"==================================================
" File: SzWeather.vim
" Brief: 山寨版气象预报
" Authors: shrek<shrek.wang AT gmail DOT com>
" Last Change: 2009-02-14 21:14:00
" Version: 0.00000000000000000000000000000001
" Licence: LGPL
"
"
" Usage: 1:编辑任意文件
" 2:用 ,gw 来打开气象预报

function! GetWeather()
python << EOF
import vim
import re
import urllib

vim.command("call SwitchToWeatherResult()")
url="http://www.hzqx.com/gzhfw/dqyb.asp"
f = urllib.urlopen(url)
content = f.read()
f.close()
content=content.decode("GBK")
pattern="    "

start= content.find(pattern);
end= content.find("</td>",start);

weatherInfo=content[start:end].replace("    ","")
lines=weatherInfo.encode("UTF8").split("\n")
for line in lines:
vim.current.buffer.append(line)
EOF
endfunction

function! SwitchToWeatherResult()
let s:cur_buf = bufnr("%")
let s:szdb_result_buf=bufnr("SzdbResult")
if bufwinnr(s:szdb_result_buf) > 0
exec bufwinnr(s:szdb_result_buf) . "wincmd w"
%d
else
exec 'silent! botright split SzWeatherResult'
exec "e SzWeatherResult"
exec "set wrap"
exec "map d :bd!<cr>"
endif

endfunction

map <silent> ,gw :call GetWeather()<cr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值