版權沒有,翻印不究。
# -*- coding: UTF-8 -*- import sys, os from urllib import urlretrieve def ratio_changed(ratio, last_ratio, tick): return int(ratio/tick)-int(last_ratio/tick) > 0 last_ratio = 0. def report(block, size, total): global last_ratio ratio = float(block)*size/total*100 if ratio_changed(ratio, last_ratio, 10): sys.stdout.write("%.1f%%"%ratio) elif ratio_changed(ratio, last_ratio, 1): sys.stdout.write(".") last_ratio = ratio if len(sys.argv) < 2: sys.stdout.write("Please specify a url.\n") sys.exit() url = sys.argv[1] filename = url.split('/')[-1] os.unlink(filename) sys.stdout.write("[start]") urlretrieve(url,filename,report) sys.stdout.write("[done]\n") sys.stdout.write("%s saved.\n"%filename)
Posted by yungyuc
at 08:30,
0 comment,
0 trackback.
Navigate
- Previous: 窗戶下的蛇 @2007/05/30
- Next: Python 的縮排 (注意事項) @2007/06/08
Add a trackback
Please send trackback to: http://blog.seety.org/everydaywork/2007/6/5/682/trackback/.
Add a comment