Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*-coding: cp1251 -*-
- import urllib2
- import cookielib
- # time module for performance metrics
- import time
- # re module for simple replace
- import re
- # error handler for 404/401/403 and etc
- from urllib2 import HTTPError
- # let's try multithreading to speed up our app
- import thread
- start = time.time()
- inp = open("input.txt", "r")
- st = inp.read().split("\n")
- cookie = cookielib.CookieJar()
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
- urllib2.install_opener(opener)
- fn = st
- for i in xrange(len(st)):
- fn[i] = re.sub("[\?=\/]","_",fn[i][7:])
- lst = [st[0::2], st[1::2]]
- fnlist = [fn[0::2], fn[1::2]]
- l = [len(lst[0]), len(lst[1])]
- c = [0, 0]
- def f1(threadnum):
- while(c[threadnum]<l[threadnum]):
- #assert threadnum>=0 and threadnum<=1
- a = lst[threadnum][c[threadnum]]
- fname = fnlist[threadnum][c[threadnum]]
- c[threadnum]+=1
- try:
- out=open("".join(fname[7:])+".txt", "w")
- site = urllib2.urlopen(a)
- print(site.read())
- out.close()
- except HTTPError, e:
- print e.code
- try:
- thread.start_new_thread( f1, (0, ) )
- thread.start_new_thread( f1, (1, ) )
- except Exception, e:
- print e
- print "Failed to create new thread"
- end = time.time()
- print "Elapsed Time: %s" % (end - start)
Advertisement
Add Comment
Please, Sign In to add comment