Allow user to run multiple script file
start_script()
stop_script()
time stamp with the textfile
Below the instead of url need to run script file
create a log file with the timestamp
Please help out if anyone with above the code
What I have tried:
import requests
import time
import threading
urls = [
'https://images.pexels.com/photos/305821/pexels-photo-305821.jpeg',
'https://images.pexels.com/photos/509922/pexels-photo-509922.jpeg',
'https://images.pexels.com/photos/325812/pexels-photo-325812.jpeg',
'https://images.pexels.com/photos/1252814/pexels-photo-1252814.jpeg',
'https://images.pexels.com/photos/1420709/pexels-photo-1420709.jpeg',
'https://images.pexels.com/photos/963486/pexels-photo-963486.jpeg',
'https://images.pexels.com/photos/1557183/pexels-photo-1557183.jpeg',
'https://images.pexels.com/photos/3023211/pexels-photo-3023211.jpeg',
'https://images.pexels.com/photos/1031641/pexels-photo-1031641.jpeg',
'https://images.pexels.com/photos/439227/pexels-photo-439227.jpeg',
'https://images.pexels.com/photos/696644/pexels-photo-696644.jpeg',
'https://images.pexels.com/photos/911254/pexels-photo-911254.jpeg',
'https://images.pexels.com/photos/1001990/pexels-photo-1001990.jpeg',
'https://images.pexels.com/photos/3518623/pexels-photo-3518623.jpeg',
'https://images.pexels.com/photos/916044/pexels-photo-916044.jpeg'
]
def download(url):
img_data = requests.get(url).content
img_name = url.split('/')[4]
img_name = f'{img_name}.jpg'
with open(img_name, 'wb') as img_file:
img_file.write(img_data)
print(f'downloading {img_name}')
start = time.perf_counter()
threads = []
for i in urls:
t = threading.Thread(target=download, args=[i])
t.start()
threads.append(t)
for thread in threads:
thread.join()
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} seconds')