File tree 1 file changed +6
-6
lines changed
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -7,10 +7,10 @@ def read_urls_from_csv(csv_file, column_name):
7
7
try :
8
8
# Read CSV file into a DataFrame
9
9
image_data = pd .read_csv (csv_file )
10
-
10
+
11
11
# Extract URLs from specified column
12
12
urls = image_data [column_name ].tolist ()
13
-
13
+
14
14
return urls
15
15
except FileNotFoundError as e :
16
16
print (f"File not found: { e } " )
@@ -24,19 +24,19 @@ def download_image(url, folder):
24
24
# Send a GET request to the URL with a timeout
25
25
response = requests .get (url , stream = True , timeout = 10 )
26
26
response .raise_for_status ()
27
-
27
+
28
28
# Generate a unique filename using the URL
29
29
filename = quote_plus (url )[:25 ] # Limit filename length
30
30
filename = f"{ filename } .jpg"
31
-
31
+
32
32
# Create the output path
33
33
output_path = os .path .join (folder , filename )
34
-
34
+
35
35
# Save the image to the specified folder
36
36
with open (output_path , 'wb' ) as file :
37
37
for chunk in response .iter_content (8192 ):
38
38
file .write (chunk )
39
-
39
+
40
40
print (f"Downloaded: { url } to { output_path } " )
41
41
except requests .exceptions .RequestException as e :
42
42
print (f"Failed to download { url } : { e } " )
You can’t perform that action at this time.
0 commit comments