def main():
	"""
		Main function
	"""
	try:
		ts = time()
		print("Start")
		url = "http://xkcd.com/1629/"
		directory = download.setupdir()
		url1 = int(url[-5:-1])
		url2 = url1 - 1
		url3 = url1 - 2
		url4 = url1 - 3
		
		
		threads = []

		thread1 = Downloader(directory, url1, 1)
		thread2 = Downloader(directory, url2, 2)
		thread3 = Downloader(directory, url3, 3)
		thread4 = Downloader(directory, url4, 4)
		
		thread1.start()
		thread2.start()
		thread3.start()
		thread4.start()
		
		threads.append(thread1)
		threads.append(thread2)
		threads.append(thread3)
		threads.append(thread4)

		for t in threads:
			t.join()
		
		print("We are done!")		
		print("Time taken: {}s".format(time() - ts))
			
	except KeyboardInterrupt:
		print("\n\n--------\nGoodbye\n--------\n")
		sys.exit(0)
Exemplo n.º 2
0
def main():
	try:
		ts = time()
		print("Start")
		url = "http://xkcd.com/1629/"
		directory = download.setupdir()
		urlrange = int(url[-5:-1])
		url = url[0:-5]
					
		for i in range(urlrange, 0, -1):
			print("Downloading image number {}".format(i))
			url = "http://xkcd.com/" + str(i)
			print("url: {}".format(url))
			try:
				download.getlink(url, directory, i)
				print("Downloaded\n")
			except Exception as e:
				url = url[0:-5]
				
		print("Time taken: {}s".format(time() - ts))
			
	except KeyboardInterrupt:
		print("\n\n--------\nGoodbye\n--------\n")
		sys.exit(0)
Exemplo n.º 3
0
def main():
    try:
        ts = time()
        print("Start")
        url = "http://xkcd.com/1629/"
        directory = download.setupdir()
        urlrange = int(url[-5:-1])
        url = url[0:-5]

        for i in range(urlrange, 0, -1):
            print("Downloading image number {}".format(i))
            url = "http://xkcd.com/" + str(i)
            print("url: {}".format(url))
            try:
                download.getlink(url, directory, i)
                print("Downloaded\n")
            except Exception as e:
                url = url[0:-5]

        print("Time taken: {}s".format(time() - ts))

    except KeyboardInterrupt:
        print("\n\n--------\nGoodbye\n--------\n")
        sys.exit(0)