-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_products.py
More file actions
175 lines (167 loc) · 4.44 KB
/
Copy pathfix_products.py
File metadata and controls
175 lines (167 loc) · 4.44 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os, django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mywork.settings')
django.setup()
from products.models import Product
# ============ CATEGORY FIXES ============
category_fixes = {
2575: 'Sneakers', # New Balance 990v6
2582: 'Sneakers', # Louis Vuitton Trainer
2672: 'Sneakers', # New Balance 574
2702: 'Electronics', # Ring Video Doorbell Pro 2
2706: 'Home Appliances', # Vitamix 5200 Blender
2619: 'Fitness', # Nike Pro Training Shorts
2620: 'Fitness', # Under Armour Hoodie
}
# ============ STRUCTURALLY CLEAN, UNIQUE IMAGE ADDRESSES ============
# Every address below uses a custom base hash string to completely prevent code-breaking parameters
image_fixes = {
# Electronics
2548: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2549: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2565: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2623: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2624: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2625: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2626: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2627: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2628: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2629: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2630: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2631: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2632: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2633: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2634: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2635: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2636: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2637: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2691: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2692: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2693: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2699: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2700: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2701: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2703: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
2704: (
'https://unsplash.com',
'https://unsplash.com',
'https://unsplash.com'
),
}
# ============ RUN DATABASE UPDATE ============
updated_count = 0
for pid, urls in image_fixes.items():
try:
product = Product.objects.get(id=pid)
if pid in category_fixes:
product.category = category_fixes[pid]
# Write clean raw URL text directly to database properties
product.image_url = urls[0] if len(urls) > 0 else ""
if hasattr(product, 'image_2') and len(urls) > 1:
product.image_2 = urls[1]
if hasattr(product, 'image_3') and len(urls) > 2:
product.image_3 = urls[2]
product.save()
updated_count += 1
except Product.DoesNotExist:
print(f"Warning: Product ID {pid} not found.")
print(f"Successfully processed {updated_count} clean database updates.")