-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_image_function.py
More file actions
34 lines (26 loc) · 1.14 KB
/
add_image_function.py
File metadata and controls
34 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import csv
print("Starting CSV modification...")
try:
# Read the existing CSV and create a new one with modified URLs
with open('injectables_with_images.csv', 'r', encoding='utf-8') as input_file, \
open('injectables_with_images_with_function.csv', 'w', newline='', encoding='utf-8') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)
# Write header row
header = next(reader)
writer.writerow(header)
# Process each row
row_count = 0
for row in reader:
product_name = row[0]
image_url = row[1]
# Wrap the URL in the IMAGE function
image_formula = f'=IMAGE("{image_url}")'
writer.writerow([product_name, image_formula])
row_count += 1
print(f"Successfully processed {row_count} rows")
print(f"New file created: injectables_with_images_with_function.csv")
except FileNotFoundError:
print("Error: Could not find injectables_with_images.csv in the current directory")
except Exception as e:
print(f"An error occurred: {str(e)}")