File packages/item_upload.py changed (mode: 100644) (index 7b74184..730dbcf) |
... |
... |
def itemPropertyUpload(flatfile, folder, filename): |
221 |
221 |
reader = csv.DictReader(item, delimiter=';', lineterminator='\n') |
reader = csv.DictReader(item, delimiter=';', lineterminator='\n') |
222 |
222 |
|
|
223 |
223 |
# define the names of the property fields within the flatfile |
# define the names of the property fields within the flatfile |
224 |
|
property_names = ['bullet_point1', 'bullet_point2' |
|
225 |
|
, 'bullet_point3', 'bullet_point4' |
|
226 |
|
, 'bullet_point5', 'fit_type' |
|
227 |
|
, 'lifestyle', 'batteries_required' |
|
228 |
|
, 'supplier_declared_dg_hz_regulation' |
|
229 |
|
, 'department_name', 'variation_theme' |
|
230 |
|
, 'seasons', 'material_composition' |
|
231 |
|
, 'outer_material_type', 'collar_style' |
|
232 |
|
, 'neck_size', 'pattern_type' |
|
233 |
|
, 'sleeve_type'] |
|
|
224 |
|
property_names = ['bullet_point1', 'bullet_point2', |
|
225 |
|
'bullet_point3', 'bullet_point4', |
|
226 |
|
'bullet_point5', 'fit_type', |
|
227 |
|
'lifestyle', 'batteries_required', |
|
228 |
|
'supplier_declared_dg_hz_regulation1', |
|
229 |
|
'department_name', 'variation_theme', |
|
230 |
|
'seasons', 'material_composition', |
|
231 |
|
'outer_material_type', 'collar_style', |
|
232 |
|
'neck_size', 'pattern_type', |
|
233 |
|
'sleeve_type', 'installation_type', |
|
234 |
|
'finish_type', 'seasons1', 'paint_type1', |
|
235 |
|
'theme'] |
234 |
236 |
|
|
235 |
237 |
# Assign the Plentymarkets property ID to the property_names |
# Assign the Plentymarkets property ID to the property_names |
236 |
238 |
property_id = dict() |
property_id = dict() |
237 |
239 |
|
|
238 |
|
id_values = ['15', '16' |
|
239 |
|
, '17', '24' |
|
240 |
|
, '19', '20' |
|
241 |
|
, '9', '10' |
|
242 |
|
, '14' |
|
243 |
|
, '13', '12' |
|
244 |
|
, '11', '8' |
|
245 |
|
, '7', '25' |
|
246 |
|
, '26', '28' |
|
247 |
|
, '29'] |
|
248 |
|
|
|
|
240 |
|
use_names = [] |
|
241 |
|
id_values = ['15', '16', |
|
242 |
|
'17', '24', |
|
243 |
|
'19', '20', |
|
244 |
|
'9', '10', |
|
245 |
|
'14', |
|
246 |
|
'13', '12', |
|
247 |
|
'11', '8', |
|
248 |
|
'7', '25', |
|
249 |
|
'26', '28', |
|
250 |
|
'29', '45', |
|
251 |
|
'46', '47', |
|
252 |
|
'48', '49'] |
249 |
253 |
property_id = dict( zip(property_names, id_values) ) |
property_id = dict( zip(property_names, id_values) ) |
250 |
254 |
|
|
251 |
255 |
properties = dict() |
properties = dict() |
|
... |
... |
def itemPropertyUpload(flatfile, folder, filename): |
253 |
257 |
for row in reader: |
for row in reader: |
254 |
258 |
if(row['parent_child'] == 'parent'): |
if(row['parent_child'] == 'parent'): |
255 |
259 |
try: |
try: |
256 |
|
values = [row[property_names[0]], row[property_names[1]] |
|
257 |
|
, row[property_names[2]], row[property_names[3]] |
|
258 |
|
, row[property_names[4]], row[property_names[5]] |
|
259 |
|
, row[property_names[6]], row[property_names[7]] |
|
260 |
|
, row[property_names[8] + '1'] |
|
261 |
|
, row[property_names[9]], row[property_names[10]] |
|
262 |
|
, row[property_names[11]], row[property_names[12]] |
|
263 |
|
, row[property_names[13]], row[property_names[14]] |
|
264 |
|
, row[property_names[15]], row[property_names[16]] |
|
265 |
|
, row[property_names[17]] |
|
266 |
|
] |
|
|
260 |
|
use_names = [i for i in property_names if i in [*row]] |
|
261 |
|
values = [row[i] for i in use_names] |
267 |
262 |
except ValueError as err: |
except ValueError as err: |
268 |
263 |
print("In property Upload: One of the values wasn't found : ", err) |
print("In property Upload: One of the values wasn't found : ", err) |
269 |
264 |
|
|
270 |
265 |
# Check for empty values |
# Check for empty values |
271 |
|
properties[row['item_sku']] = dict(zip(property_names, values)) |
|
|
266 |
|
properties[row['item_sku']] = dict(zip(use_names, values)) |
272 |
267 |
|
|
273 |
268 |
column_names = ['SKU', 'ID-property', 'Value', 'Lang', 'Active'] |
column_names = ['SKU', 'ID-property', 'Value', 'Lang', 'Active'] |
274 |
269 |
Data = {} |
Data = {} |
275 |
270 |
for index, row in enumerate( properties ): |
for index, row in enumerate( properties ): |
276 |
|
for prop in property_id: |
|
277 |
|
values = [row, property_id[prop], properties[row][prop], 'DE', 1] |
|
|
271 |
|
for prop in use_names: |
|
272 |
|
try: |
|
273 |
|
values = [row, property_id[prop], |
|
274 |
|
properties[row][prop], 'DE', 1] |
278 |
275 |
|
|
279 |
|
Data[row + prop] = dict(zip(column_names, values)) |
|
|
276 |
|
Data[row + prop] = dict(zip(column_names, values)) |
|
277 |
|
except KeyError as kerr: |
|
278 |
|
print("ERROR: Key {0} was not found in the flatfile" |
|
279 |
|
.format(kerr)) |
280 |
280 |
|
|
281 |
281 |
|
|
282 |
282 |
barcode.writeCSV(Data, "Item_Merkmale", column_names, folder, filename) |
barcode.writeCSV(Data, "Item_Merkmale", column_names, folder, filename) |
|
... |
... |
def get_attributes(dataset, sets): |
335 |
335 |
|
|
336 |
336 |
output_string = '' |
output_string = '' |
337 |
337 |
try: |
try: |
338 |
|
if(len(sets[dataset['parent_sku']]['color']) > 1): |
|
339 |
|
output_string = 'color_name:' + dataset['color_name'] |
|
|
338 |
|
if(dataset['parent_sku'] in [*sets]): |
|
339 |
|
if(len(sets[dataset['parent_sku']]['color']) > 1): |
|
340 |
|
output_string = 'color_name:' + dataset['color_name'] |
|
341 |
|
else: |
|
342 |
|
print("{0} not found in {1}".format( |
|
343 |
|
dataset['parent_sku'], ','.join([*sets]) |
|
344 |
|
)) |
340 |
345 |
except Exception as err: |
except Exception as err: |
341 |
346 |
print("Error @ adding color to string (get_attributes)\nerr:{0}" |
print("Error @ adding color to string (get_attributes)\nerr:{0}" |
342 |
347 |
.format(err)) |
.format(err)) |
|
... |
... |
def find_similar_attr(flatfile): |
360 |
365 |
|
|
361 |
366 |
for row in reader: |
for row in reader: |
362 |
367 |
# If it is a parent create a new dictionary with 2 sets for color and size |
# If it is a parent create a new dictionary with 2 sets for color and size |
363 |
|
if(row['parent_child'] == 'parent'): |
|
|
368 |
|
if(row['parent_child'].lower() == 'parent'): |
364 |
369 |
color = set() |
color = set() |
365 |
370 |
size = set() |
size = set() |
366 |
371 |
Data[row['item_sku']] = {'color':color, 'size':size} |
Data[row['item_sku']] = {'color':color, 'size':size} |