Sent: Friday, August 30, 2002 3:45 PM
> - lib.ru
> . ,
> , .
> :
> libru.py http://www.lib.ru/DOWLATOW/chemodan.txt
> , ,
> initproxy().
import sys, re, StringIO, gzip, zipfile, urllib2
def initproxy():
proxy_support = urllib2.ProxyHandler({"http" : "http://user:password@proxy.domain.ru:3128"})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)
def doprepare(text):
text = text.replace("\024", "").replace("\025",".\r\n").replace("\241","")
text = re.sub(r"[ \t]+", " ", text)
text = re.sub(r"[\f\v]+", "\r\n", text)
text = re.sub(r"(?s)-{63,}.{1,500}-{63,}", "\r\n", text, 1)
parags = [re.sub(r"\s+", " ", p) for p in re.split(r"(?m)^\s", text)]
text = "\r\n ".join(parags)
return text
def download(url):
data = urllib2.urlopen(url + ".gz").read()
return data
def handleurl(url):
inname = url.split("/")[-1]
text = gzip.GzipFile(fileobj = StringIO.StringIO(download(url))).read()
zf = zipfile.ZipFile(inname.split('.')[0] + ".zip", "w")
info = zipfile.ZipInfo(inname)
info.compress_type = zipfile.ZIP_DEFLATED
zf.writestr(info, doprepare(text))
if __name__ == '__main__':
initproxy()
handleurl(sys.argv[1])
Last-modified: Thu, 05 Sep 2002 14:32:13 GMT