Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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')
Posted
Comments
Richard MacCutchan 1-Nov-22 10:44am    
And what is the problem?
HelpMewithCode 1-Nov-22 11:40am    
'https//pexels-photo-305821.jpeg', instead of jpeg , i need to run .py file at time
Example:
C:/user/demo.py file
C:/user/demo2.py file
HelpMewithCode 2-Nov-22 1:47am    
Can you help me out this ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900