Have you tried any code? Please share if you have. From what you describe, there are three main goals: 1) open and read the CSV file, 2) download the image 3) rename the file. I'll give you general direction for each part, but it's up to you to complete the full code:
1) Open CSV and read data: Python has a specific library for CSV: CSV File Read and Write
Here is an example using csv.DictReader
. You will have to modify for your specific CSV file format:
import csv
with open('filename.csv', 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
image_url = row['ImageURL'] # replace with your column heading
filename = row['Name'] # replace with your column heading
2) Download image from web: You can use urllib.urlretrieve
to download the image. Example:
import urllib
urllib.urlretrieve(image_url, filename)
3) Rename file. The above code will retrieve the url and save as filename
, so maybe you do not need to do this step. If you still do, then os.rename(src, dst)
will do the trick.
Hope this helps. Best of luck to you. Use plenty of print
statements to debug your code. The Python documentation is your friend.