stdin输入一行一个附件链接,Ctrl+D后会调用curl开始下载(希望显示下载进度,还得在header里读取文件名,懒得用urllib2搞了)
#!/usr/bin/env python2.7
import re
import sys
import subprocess as subp
ptn = re.compile(r'^{0}([\w\d]+)&fid=61$'.format(re.escape(r'http://www.itpub.net/attachment.php?aid=')))
for line in sys.stdin:
line = line.strip()
if line:
mat = ptn.match(line)
if mat is not None:
filelink='http://www.itpub.net/forum.php?mod=attachment&aid={0}==&fid=61'.format(mat.group(1))
subp.call(['curl', '-JOL', filelink])