hashir672/nts-http-672
0
1from flask import Flask2import grequests3import time4import threading5class Unbuffered(object):6 def __init__(self, stream):7 self.stream = stream8 def write(self, data):9 self.stream.write(data)10 self.stream.flush()11 def writelines(self, datas):12 self.stream.writelines(datas)13 self.stream.flush()14 def __getattr__(self, attr):15 return getattr(self.stream, attr)16import sys17sys.stdout = Unbuffered(sys.stdout)18 19def myfunc():20 num = 100021 url = "https://storage.nts.org.pk/upload/565510/userpic/565510_"22 thislist = ["https://storage.nts.org.pk/upload/565510/userpic/565510_1000.jpg"]23 while True:24 num=num+125 new_url = url+str(num)+".jpg"26 27 thislist.append(new_url)28 if(num==10000):29 30 break31 print("list completed")32 # start_time = time.time()33 34 urls = thislist35 rs = (grequests.head(u) for u in urls)36 x=100037 for response in grequests.map(rs):38 x=x+139 # print(response.status_code, response.elapsed.total_seconds())40 if(response.status_code==200):41 print("Got it at "+str(x))42 43 44app = Flask(__name__)45 46 47@app.route('/')48def hello_world():49 50 return 'Hello World'51@app.route('/start')52def started():53 t1 = threading.Thread(target=myfunc)54 t1.start()55 return 'Started'56 57if __name__ == '__main__':58 59 60 app.run()61 