File packages/image_upload.py changed (mode: 100644) (index 439c2c9..8cba657) |
... |
... |
import re |
3 |
3 |
import sys |
import sys |
4 |
4 |
import inspect |
import inspect |
5 |
5 |
from sortedcontainers import SortedDict |
from sortedcontainers import SortedDict |
6 |
|
from packages import item_upload, barcode |
|
7 |
|
from packages.item_upload import errorPrint, warnPrint |
|
|
6 |
|
from packages import item_upload, barcode, error |
8 |
7 |
|
|
9 |
8 |
def searchSpecialImage(image): |
def searchSpecialImage(image): |
10 |
9 |
return bool(re.search(r'( SWATCH|SIZE )', image)) |
return bool(re.search(r'( SWATCH|SIZE )', image)) |
|
... |
... |
def getColorAttributeID(attributefile, product): |
21 |
20 |
if row['AttributeValue.backendName'] == product['color_name']: |
if row['AttributeValue.backendName'] == product['color_name']: |
22 |
21 |
attributeid = row['AttributeValue.id'] |
attributeid = row['AttributeValue.id'] |
23 |
22 |
if not attributeid: |
if not attributeid: |
24 |
|
warn = f"Color:{product['color_name']} not found in {product['item_sku']}!\n" |
|
25 |
|
warnPrint(warn, |
|
26 |
|
inspect.currentframe().f_back.f_lineno) |
|
|
23 |
|
warn =\ |
|
24 |
|
f"Color{product['color_name']} not in {product['item_sku']}\n" |
|
25 |
|
error.warnPrint( |
|
26 |
|
msg=warn, |
|
27 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
27 |
28 |
except KeyError as err: |
except KeyError as err: |
28 |
|
errorPrint("key not found in attribute file", err, |
|
29 |
|
sys.exc_info()[2].tb_lineno) |
|
|
29 |
|
error.errorPrint( |
|
30 |
|
msg="key not found in attribute file", |
|
31 |
|
err=err, |
|
32 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
30 |
33 |
|
|
31 |
34 |
return attributeid |
return attributeid |
32 |
35 |
|
|
|
... |
... |
def imageUpload(flatfile, attributefile, exportfile, uploadfolder, filename): |
82 |
85 |
|
|
83 |
86 |
|
|
84 |
87 |
except Exception as err: |
except Exception as err: |
85 |
|
errorPrint("Link string building failed", err, |
|
86 |
|
sys.exc_info()[2].tb_lineno) |
|
|
88 |
|
error.errorPrint(msg="Link string building failed", |
|
89 |
|
err=err, |
|
90 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
87 |
91 |
|
|
88 |
92 |
try: |
try: |
89 |
93 |
attribute_id = getColorAttributeID( |
attribute_id = getColorAttributeID( |
90 |
94 |
attributefile=attributefile, product=row) |
attributefile=attributefile, product=row) |
91 |
95 |
except Exception as err: |
except Exception as err: |
92 |
|
warnPrint( |
|
93 |
|
f"get attribute ID of color {row['color_name']} failed", |
|
|
96 |
|
error.warnPrint( |
|
97 |
|
msg=f"get attr ID of color {row['color_name']} failed", |
94 |
98 |
linenumber=inspect.currentframe().f_back.f_lineno, |
linenumber=inspect.currentframe().f_back.f_lineno, |
95 |
99 |
err=err) |
err=err) |
96 |
100 |
|
|
|
... |
... |
def imageUpload(flatfile, attributefile, exportfile, uploadfolder, filename): |
101 |
105 |
data[row['item_sku']] = dict(zip(column_names, values)) |
data[row['item_sku']] = dict(zip(column_names, values)) |
102 |
106 |
|
|
103 |
107 |
except Exception as err: |
except Exception as err: |
104 |
|
errorPrint(f"flatfile read failed on index:{index}", |
|
105 |
|
err, sys.exc_info()[2].tb_lineno) |
|
|
108 |
|
error.errorPrint( |
|
109 |
|
msg=f"flatfile read failed on index:{index}", |
|
110 |
|
err=err, |
|
111 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
106 |
112 |
|
|
107 |
113 |
barcode.writeCSV(dataobject=data, name='Image_', columns=column_names, |
barcode.writeCSV(dataobject=data, name='Image_', columns=column_names, |
108 |
114 |
upload_path=uploadfolder, item=filename) |
upload_path=uploadfolder, item=filename) |
File packages/item_upload.py changed (mode: 100644) (index 85715b1..381919e) |
... |
... |
import re |
4 |
4 |
import collections |
import collections |
5 |
5 |
import inspect |
import inspect |
6 |
6 |
import chardet |
import chardet |
7 |
|
import colorama |
|
8 |
|
from packages import barcode, amazon_data_upload, price_upload |
|
|
7 |
|
from packages import barcode, amazon_data_upload, price_upload, error |
9 |
8 |
|
|
10 |
9 |
|
|
11 |
10 |
class WrongEncodingException(Exception): |
class WrongEncodingException(Exception): |
12 |
11 |
pass |
pass |
13 |
12 |
|
|
14 |
|
try: |
|
15 |
|
def errorPrint(msg, err, linenumber): |
|
16 |
|
print(colorama.Fore.LIGHTRED_EX) |
|
17 |
|
if err: |
|
18 |
|
print("ERROR:\nline:{0}\t{1}\tError:{2}" |
|
19 |
|
.format(linenumber, msg, err)) |
|
20 |
|
else: |
|
21 |
|
print("ERROR:\nline:{0}\t{1}" |
|
22 |
|
.format(linenumber, msg)) |
|
23 |
|
print(colorama.Style.RESET_ALL) |
|
24 |
|
except AttributeError: |
|
25 |
|
def errorPrint(msg, err, linenumber): |
|
26 |
|
if err: |
|
27 |
|
print("ERROR:\nline:{0}\t{1}\tError:{2}" |
|
28 |
|
.format(linenumber, msg, err)) |
|
29 |
|
else: |
|
30 |
|
print("ERROR:\nline:{0}\t{1}" |
|
31 |
|
.format(linenumber, msg)) |
|
32 |
|
|
|
33 |
|
try: |
|
34 |
|
def warnPrint(msg, err, linenumber): |
|
35 |
|
print(colorama.Fore.YELLOW) |
|
36 |
|
if err: |
|
37 |
|
print("WARNING:\nline:{0}\t{1}\tWarning:{2}" |
|
38 |
|
.format(linenumber, msg, err)) |
|
39 |
|
else: |
|
40 |
|
print("WARNING:\nline:{0}\t{1}" |
|
41 |
|
.format(linenumber, msg)) |
|
42 |
|
print(colorama.Style.RESET_ALL) |
|
43 |
|
except AttributeError: |
|
44 |
|
def warnPrint(msg, linenumber, err=''): |
|
45 |
|
if err: |
|
46 |
|
print("WARNING:\nline:{0}\t{1}\tWarning:{2}" |
|
47 |
|
.format(linenumber, msg, err)) |
|
48 |
|
else: |
|
49 |
|
print("WARNING:\nline:{0}\t{1}" |
|
50 |
|
.format(linenumber, msg)) |
|
51 |
|
|
|
52 |
|
try: |
|
53 |
|
def infoPrint(msg): |
|
54 |
|
print(colorama.Fore.LIGHTBLUE_EX) |
|
55 |
|
print(f"INFO:{msg}\n") |
|
56 |
|
print(colorama.Style.RESET_ALL) |
|
57 |
|
except AttributeError: |
|
58 |
|
def infoPrint(msg): |
|
59 |
|
print(f"INFO:{msg}\n") |
|
60 |
13 |
|
|
61 |
14 |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
62 |
15 |
column_names = ['Parent-SKU', 'SKU', |
column_names = ['Parent-SKU', 'SKU', |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
114 |
67 |
try: |
try: |
115 |
68 |
raise barcode.EmptyFieldWarning('generic_keywords') |
raise barcode.EmptyFieldWarning('generic_keywords') |
116 |
69 |
except Exception: |
except Exception: |
117 |
|
warnPrint("Generic Keywords are empty!", |
|
|
70 |
|
error.warnPrint("Generic Keywords are empty!", |
118 |
71 |
inspect.currentframe().f_back.f_lineno) |
inspect.currentframe().f_back.f_lineno) |
119 |
72 |
|
|
120 |
73 |
try: |
try: |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
130 |
83 |
if(group_parent and row['parent_sku'] == group_parent): |
if(group_parent and row['parent_sku'] == group_parent): |
131 |
84 |
position += 1 |
position += 1 |
132 |
85 |
except Exception as err: |
except Exception as err: |
133 |
|
warnPrint("Attribute setting failed", |
|
|
86 |
|
error.warnPrint("Attribute setting failed", |
134 |
87 |
sys.exc_info()[2].tb_lineno, err) |
sys.exc_info()[2].tb_lineno, err) |
135 |
88 |
try: |
try: |
136 |
89 |
values = [ |
values = [ |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
163 |
116 |
] |
] |
164 |
117 |
|
|
165 |
118 |
except KeyError as kerr: |
except KeyError as kerr: |
166 |
|
warnPrint('itemUpload: key not found in flatfile', |
|
|
119 |
|
error.warnPrint('itemUpload: key not found in flatfile', |
167 |
120 |
inspect.currentframe().f_back.f_lineno, |
inspect.currentframe().f_back.f_lineno, |
168 |
121 |
err=kerr) |
err=kerr) |
169 |
122 |
raise KeyError |
raise KeyError |
170 |
123 |
except Exception as err: |
except Exception as err: |
171 |
|
errorPrint("itemUpload: setting values failed", err, |
|
|
124 |
|
error.errorPrint("itemUpload: setting values failed", err, |
172 |
125 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
173 |
126 |
data[row['item_sku']] = collections.OrderedDict(zip(column_names, values)) |
data[row['item_sku']] = collections.OrderedDict(zip(column_names, values)) |
174 |
127 |
except KeyError as err: |
except KeyError as err: |
175 |
|
errorPrint("Reading file failed", err, |
|
|
128 |
|
error.errorPrint("Reading file failed", err, |
176 |
129 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
177 |
130 |
return row['item_sku'] |
return row['item_sku'] |
178 |
131 |
|
|
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
184 |
137 |
if row['amazon_sku'] in list(data.keys()): |
if row['amazon_sku'] in list(data.keys()): |
185 |
138 |
data[row['amazon_sku']]['ExternalID'] = row['full_number'] |
data[row['amazon_sku']]['ExternalID'] = row['full_number'] |
186 |
139 |
except KeyError as keyerr: |
except KeyError as keyerr: |
187 |
|
warnPrint("key was not found in intern number list", |
|
|
140 |
|
error.warnPrint("key was not found in intern number list", |
188 |
141 |
sys.exc_info()[2].tb_lineno, keyerr) |
sys.exc_info()[2].tb_lineno, keyerr) |
189 |
142 |
|
|
190 |
143 |
# Include the barcodes & asin |
# Include the barcodes & asin |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
199 |
152 |
data[row]['ASIN-type'] = barcode_data[row]['ASIN-type'] |
data[row]['ASIN-type'] = barcode_data[row]['ASIN-type'] |
200 |
153 |
data[row]['ASIN-value'] = barcode_data[row]['ASIN-value'] |
data[row]['ASIN-value'] = barcode_data[row]['ASIN-value'] |
201 |
154 |
except Exception as err: |
except Exception as err: |
202 |
|
errorPrint("Barcode part for "+row, err, |
|
|
155 |
|
error.errorPrint("Barcode part for "+row, err, |
203 |
156 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
204 |
157 |
|
|
205 |
158 |
# Include the amazonsku |
# Include the amazonsku |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
213 |
166 |
data[row]['amazon_sku'] = sku_data[row]['SKU'] |
data[row]['amazon_sku'] = sku_data[row]['SKU'] |
214 |
167 |
data[row]['amazon_parentsku'] = sku_data[row]['ParentSKU'] |
data[row]['amazon_parentsku'] = sku_data[row]['ParentSKU'] |
215 |
168 |
except Exception as err: |
except Exception as err: |
216 |
|
errorPrint("SKU part for "+row, err, |
|
|
169 |
|
error.errorPrint("SKU part for "+row, err, |
217 |
170 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
218 |
171 |
|
|
219 |
172 |
# Include the amazonsku |
# Include the amazonsku |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
226 |
179 |
data[row]['fba-enabled'] = ama_data[row]['ItemAmazonFBA'] |
data[row]['fba-enabled'] = ama_data[row]['ItemAmazonFBA'] |
227 |
180 |
data[row]['fba-shipping'] = ama_data[row]['ItemShippingWithAmazonFBA'] |
data[row]['fba-shipping'] = ama_data[row]['ItemShippingWithAmazonFBA'] |
228 |
181 |
except Exception as err: |
except Exception as err: |
229 |
|
errorPrint("Amazondata part for "+row, err, |
|
|
182 |
|
error.errorPrint("Amazondata part for "+row, err, |
230 |
183 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
231 |
184 |
|
|
232 |
185 |
# Include the price |
# Include the price |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
241 |
194 |
data[row]['webshop-price'] = price_data[row]['webshop'] |
data[row]['webshop-price'] = price_data[row]['webshop'] |
242 |
195 |
data[row]['etsy-price'] = price_data[row]['etsy'] |
data[row]['etsy-price'] = price_data[row]['etsy'] |
243 |
196 |
except Exception as err: |
except Exception as err: |
244 |
|
errorPrint("Price part for "+row, err, |
|
|
197 |
|
error.errorPrint("Price part for "+row, err, |
245 |
198 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
246 |
199 |
|
|
247 |
200 |
# Sort the dictionary to make sure that the parents are the first variant of each item |
# Sort the dictionary to make sure that the parents are the first variant of each item |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
249 |
202 |
|
|
250 |
203 |
barcode.writeCSV(sorted_data, "item", column_names, folder, filename) |
barcode.writeCSV(sorted_data, "item", column_names, folder, filename) |
251 |
204 |
except UnicodeDecodeError as err: |
except UnicodeDecodeError as err: |
252 |
|
errorPrint("decoding problem", err, |
|
|
205 |
|
error.errorPrint("decoding problem", err, |
253 |
206 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
254 |
207 |
print("press ENTER to continue..") |
print("press ENTER to continue..") |
255 |
208 |
input() |
input() |
|
... |
... |
def itemPropertyUpload(flatfile, folder, filename): |
301 |
254 |
[i for i in property_names if i in list(row.keys())] |
[i for i in property_names if i in list(row.keys())] |
302 |
255 |
values = [row[i] for i in use_names] |
values = [row[i] for i in use_names] |
303 |
256 |
except ValueError as err: |
except ValueError as err: |
304 |
|
warnPrint("No Value", |
|
|
257 |
|
error.warnPrint("No Value", |
305 |
258 |
sys.exc_info()[2].tb_lineno, err) |
sys.exc_info()[2].tb_lineno, err) |
306 |
259 |
|
|
307 |
260 |
# Check for empty values |
# Check for empty values |
|
... |
... |
def itemPropertyUpload(flatfile, folder, filename): |
317 |
270 |
|
|
318 |
271 |
data[row + prop] = dict(zip(column_names, values)) |
data[row + prop] = dict(zip(column_names, values)) |
319 |
272 |
except KeyError as kerr: |
except KeyError as kerr: |
320 |
|
errorPrint("Key was not found in the flatfile", kerr, |
|
|
273 |
|
error.errorPrint("Key was not found in the flatfile", kerr, |
321 |
274 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
322 |
275 |
|
|
323 |
276 |
|
|
|
... |
... |
def getProperties(flatfile): |
357 |
310 |
properties['width'] = int(float(row['package_width'])) |
properties['width'] = int(float(row['package_width'])) |
358 |
311 |
properties['weight'] = int(float(row['package_weight'])) |
properties['weight'] = int(float(row['package_weight'])) |
359 |
312 |
except ValueError as err: |
except ValueError as err: |
360 |
|
errorPrint("Parent has no package measurements", err, |
|
|
313 |
|
error.errorPrint("Parent has no package measurements", err, |
361 |
314 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
362 |
315 |
sys.exit() |
sys.exit() |
363 |
316 |
except Exception as err: |
except Exception as err: |
364 |
|
errorPrint("getProperties setting values failed", err, |
|
|
317 |
|
error.errorPrint("getProperties setting values failed", err, |
365 |
318 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
366 |
319 |
|
|
367 |
320 |
return properties |
return properties |
|
... |
... |
def getAttributes(dataset, sets): |
377 |
330 |
print("{0} not found in {1}" |
print("{0} not found in {1}" |
378 |
331 |
.format(dataset['parent_sku'], ','.join(list(sets.keys())))) |
.format(dataset['parent_sku'], ','.join(list(sets.keys())))) |
379 |
332 |
except Exception as err: |
except Exception as err: |
380 |
|
errorPrint("Adding of color attribute failed", err, |
|
|
333 |
|
error.errorPrint("Adding of color attribute failed", err, |
381 |
334 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
382 |
335 |
try: |
try: |
383 |
336 |
if len(sets[dataset['parent_sku']]['size']) > 1: |
if len(sets[dataset['parent_sku']]['size']) > 1: |
|
... |
... |
def getAttributes(dataset, sets): |
386 |
339 |
else: |
else: |
387 |
340 |
output_string = output_string + ';size_name:' + dataset['size_name'] |
output_string = output_string + ';size_name:' + dataset['size_name'] |
388 |
341 |
except Exception as err: |
except Exception as err: |
389 |
|
errorPrint("Adding of size attribute failed", err, |
|
|
342 |
|
error.errorPrint("Adding of size attribute failed", err, |
390 |
343 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
391 |
344 |
return output_string |
return output_string |
392 |
345 |
|
|
|
... |
... |
def checkFlatfile(flatfile): |
447 |
400 |
|
|
448 |
401 |
first_row = [*list(reader)[0]] |
first_row = [*list(reader)[0]] |
449 |
402 |
if len(first_row) == 1: |
if len(first_row) == 1: |
450 |
|
errorPrint("Wrong delimiter, use ';'", |
|
|
403 |
|
error.errorPrint("Wrong delimiter, use ';'", |
451 |
404 |
'False delimiter detected', |
'False delimiter detected', |
452 |
405 |
inspect.currentframe().f_back.f_lineno) |
inspect.currentframe().f_back.f_lineno) |
453 |
406 |
return False |
return False |
454 |
407 |
|
|
455 |
408 |
if not 'feed_product_type' in first_row: |
if not 'feed_product_type' in first_row: |
456 |
409 |
if 'Marke' in first_row: |
if 'Marke' in first_row: |
457 |
|
errorPrint("Only use the last of the 3 header lines", |
|
|
410 |
|
error.errorPrint("Only use the last of the 3 header lines", |
458 |
411 |
err='', |
err='', |
459 |
412 |
linenumber=inspect.currentframe() |
linenumber=inspect.currentframe() |
460 |
413 |
.f_back.f_lineno) |
.f_back.f_lineno) |
461 |
414 |
print("Please cut the first two rows from the flatfile for this script\n") |
print("Please cut the first two rows from the flatfile for this script\n") |
462 |
415 |
return False |
return False |
463 |
|
errorPrint("Wrong header line", err='', |
|
|
416 |
|
error.errorPrint("Wrong header line", err='', |
464 |
417 |
linenumber=inspect.currentframe().f_back.f_lineno) |
linenumber=inspect.currentframe().f_back.f_lineno) |
465 |
418 |
return False |
return False |
466 |
419 |
return True |
return True |
467 |
420 |
|
|
468 |
421 |
except Exception as err: |
except Exception as err: |
469 |
|
warnPrint("Flatfile check failed", |
|
|
422 |
|
error.warnPrint("Flatfile check failed", |
470 |
423 |
sys.exc_info()[2].tb_lineno, err) |
sys.exc_info()[2].tb_lineno, err) |
471 |
424 |
|
|
472 |
425 |
def checkEncoding(file_dict): |
def checkEncoding(file_dict): |
|
... |
... |
def checkEncoding(file_dict): |
476 |
429 |
raw_data = item.read() |
raw_data = item.read() |
477 |
430 |
except Exception as err: |
except Exception as err: |
478 |
431 |
print("ERROR: {0}\n".format(err)) |
print("ERROR: {0}\n".format(err)) |
479 |
|
errorPrint("check Encoding reading failed", err, |
|
|
432 |
|
error.errorPrint("check Encoding reading failed", err, |
480 |
433 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
481 |
434 |
file_dict['encoding'] = chardet.detect(raw_data)['encoding'] |
file_dict['encoding'] = chardet.detect(raw_data)['encoding'] |
482 |
435 |
print("chardet data for {0}\n{1}\n".format(file_dict['path'], chardet.detect(raw_data))) |
print("chardet data for {0}\n{1}\n".format(file_dict['path'], chardet.detect(raw_data))) |
483 |
436 |
|
|
484 |
437 |
except Exception as err: |
except Exception as err: |
485 |
|
errorPrint("check Encoding failed", err, |
|
|
438 |
|
error.errorPrint("check Encoding failed", err, |
486 |
439 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
487 |
440 |
|
|
488 |
441 |
return file_dict |
return file_dict |
|
... |
... |
def getVariationId(exportfile, sku): |
509 |
462 |
row[list(row.keys())[i]])) |
row[list(row.keys())[i]])) |
510 |
463 |
variationid = row[list(row.keys())[i]] |
variationid = row[list(row.keys())[i]] |
511 |
464 |
except Exception as err: |
except Exception as err: |
512 |
|
errorPrint("Looking for irregularities in getVariationId", |
|
|
465 |
|
error.errorPrint("Looking for irregularities in getVariationId", |
513 |
466 |
err, sys.exc_info()[2].tb_lineno) |
err, sys.exc_info()[2].tb_lineno) |
514 |
467 |
print("press ENTER to continue...") |
print("press ENTER to continue...") |
515 |
468 |
input() |
input() |
516 |
469 |
if not variationid: |
if not variationid: |
517 |
|
warnPrint(msg="No Variation ID found for "+sku, |
|
|
470 |
|
error.warnPrint(msg="No Variation ID found for "+sku, |
518 |
471 |
linenumber=inspect.currentframe().f_back.f_lineno) |
linenumber=inspect.currentframe().f_back.f_lineno) |
519 |
472 |
|
|
520 |
473 |
return variationid |
return variationid |