File packages/item_upload.py changed (mode: 100644) (index 3a96ba1..bc4ebd3) |
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
31 |
31 |
] |
] |
32 |
32 |
|
|
33 |
33 |
data = dict() |
data = dict() |
|
34 |
|
package_properties = dict() |
|
35 |
|
color_size_sets = dict() |
|
36 |
|
barcode_data = dict() |
34 |
37 |
sorted_data = collections.OrderedDict() |
sorted_data = collections.OrderedDict() |
35 |
|
package_properties = {} |
|
36 |
|
barcode_data = {} |
|
37 |
|
is_parent = False |
|
|
38 |
|
group_parent = '' |
38 |
39 |
position = 0 |
position = 0 |
39 |
40 |
item_price = 0 |
item_price = 0 |
|
41 |
|
is_parent = False |
40 |
42 |
|
|
41 |
|
color_size_sets = {} |
|
42 |
43 |
color_size_sets = findSimilarAttr(flatfile, ['size_name']) |
color_size_sets = findSimilarAttr(flatfile, ['size_name']) |
43 |
44 |
|
|
44 |
|
package_properties = getProperties(flatfile) |
|
45 |
|
group_parent = '' |
|
|
45 |
|
package_properties = get_properties(flatfile) |
46 |
46 |
|
|
47 |
47 |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
48 |
48 |
reader = csv.DictReader(item, delimiter=";") |
reader = csv.DictReader(item, delimiter=";") |
49 |
49 |
|
|
50 |
50 |
for row in reader: |
for row in reader: |
51 |
|
try: |
|
52 |
|
keywords = '' |
|
53 |
|
if row['generic_keywords']: |
|
54 |
|
keywords = row['generic_keywords'] |
|
55 |
|
|
|
56 |
|
if not keywords: |
|
57 |
|
raise barcode.EmptyFieldWarning('generic_keywords') |
|
58 |
|
|
|
59 |
|
item_price = row['standard_price'] |
|
60 |
|
if not item_price and row['parent_child'] == 'parent': |
|
61 |
|
item_price = price.find_price(flatfile, row['item_sku']) |
|
62 |
|
if item_price == -1: |
|
63 |
|
if os.name == 'nt': |
|
64 |
|
print("press ENTER to continue..") |
|
65 |
|
input() |
|
66 |
|
sys.exit(1) |
|
67 |
|
if item_price == '': |
|
68 |
|
error.warnPrint( |
|
69 |
|
msg=str(f"{row['item_sku']}, has no price"), err='', |
|
70 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
|
51 |
|
keywords = '' |
|
52 |
|
if row['generic_keywords']: |
|
53 |
|
keywords = row['generic_keywords'] |
|
54 |
|
|
|
55 |
|
if not keywords: |
|
56 |
|
raise barcode.EmptyFieldWarning('generic_keywords') |
|
57 |
|
|
|
58 |
|
item_price = row['standard_price'] |
|
59 |
|
if not item_price and row['parent_child'] == 'parent': |
|
60 |
|
item_price = price.find_price(flatfile, row['item_sku']) |
|
61 |
|
if item_price == -1: |
|
62 |
|
if os.name == 'nt': |
|
63 |
|
print("press ENTER to continue..") |
|
64 |
|
input() |
|
65 |
|
sys.exit(1) |
|
66 |
|
if item_price == '': |
|
67 |
|
error.warnPrint( |
|
68 |
|
msg=str(f"{row['item_sku']}, has no price"), err='', |
|
69 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
71 |
70 |
|
|
72 |
71 |
|
|
73 |
|
try: |
|
74 |
|
attributes = '' |
|
75 |
|
if row['parent_child'] == 'parent': |
|
76 |
|
is_parent = True |
|
77 |
|
group_parent = row['item_sku'] |
|
78 |
|
position = 0 |
|
79 |
|
if row['parent_child'] == 'child': |
|
80 |
|
is_parent = False |
|
81 |
|
attributes = getAttributes(dataset=row, |
|
82 |
|
sets=color_size_sets) |
|
83 |
|
if(group_parent and row['parent_sku'] == group_parent): |
|
84 |
|
position += 1 |
|
85 |
|
except Exception as err: |
|
86 |
|
error.warnPrint(msg="Attribute setting failed", err='', |
|
87 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
|
88 |
|
try: |
|
89 |
|
values = [ |
|
90 |
|
row['parent_sku'], row['item_sku'], |
|
91 |
|
is_parent, |
|
92 |
|
package_properties['length'] * 10, |
|
93 |
|
package_properties['width'] * 10, |
|
94 |
|
package_properties['height'] * 10, |
|
95 |
|
package_properties['weight'], |
|
96 |
|
row['item_name'], '104', |
|
97 |
|
attributes, position, |
|
98 |
|
keywords, |
|
99 |
|
input_data['name'], row['product_description'], |
|
100 |
|
'', # externalID |
|
101 |
|
input_data['categories'], |
|
102 |
|
input_data['categories'][0:3], input_data['categories'][0:3], |
|
103 |
|
'', '', # barcode |
|
104 |
|
'', '', # market & accout id amazonsku |
|
105 |
|
'', '', # sku & parentsku amazonsku |
|
106 |
|
amazon.get_producttype_id(source=flatfile, |
|
107 |
|
sku=row['item_sku']), |
|
108 |
|
item_price, # prices |
|
109 |
|
'', '', '', #asin |
|
110 |
|
input_data['marking'] |
|
111 |
|
] |
|
|
72 |
|
try: |
|
73 |
|
attributes = '' |
|
74 |
|
if row['parent_child'] == 'parent': |
|
75 |
|
is_parent = True |
|
76 |
|
group_parent = row['item_sku'] |
|
77 |
|
position = 0 |
|
78 |
|
if row['parent_child'] == 'child': |
|
79 |
|
is_parent = False |
|
80 |
|
attributes = getAttributes(dataset=row, |
|
81 |
|
sets=color_size_sets) |
|
82 |
|
if(group_parent and row['parent_sku'] == group_parent): |
|
83 |
|
position += 1 |
|
84 |
|
except Exception as err: |
|
85 |
|
error.warnPrint(msg="Attribute setting failed", err='', |
|
86 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
|
87 |
|
try: |
|
88 |
|
values = [ |
|
89 |
|
row['parent_sku'], row['item_sku'], |
|
90 |
|
is_parent, |
|
91 |
|
package_properties['length'] * 10, |
|
92 |
|
package_properties['width'] * 10, |
|
93 |
|
package_properties['height'] * 10, |
|
94 |
|
package_properties['weight'], |
|
95 |
|
row['item_name'], '104', |
|
96 |
|
attributes, position, |
|
97 |
|
keywords, |
|
98 |
|
input_data['name'], row['product_description'], |
|
99 |
|
'', # externalID |
|
100 |
|
input_data['categories'], |
|
101 |
|
input_data['categories'][0:3], input_data['categories'][0:3], |
|
102 |
|
'', '', # barcode |
|
103 |
|
'', '', # market & accout id amazonsku |
|
104 |
|
'', '', # sku & parentsku amazonsku |
|
105 |
|
amazon.get_producttype_id(source=flatfile, |
|
106 |
|
sku=row['item_sku']), |
|
107 |
|
item_price, # prices |
|
108 |
|
'', '', '', #asin |
|
109 |
|
input_data['marking'] |
|
110 |
|
] |
112 |
111 |
|
|
113 |
|
except KeyError as kerr: |
|
114 |
|
error.warnPrint( |
|
115 |
|
msg='itemUpload: key not found in flatfile', err=kerr, |
|
116 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
117 |
|
raise KeyError |
|
118 |
|
except Exception as err: |
|
119 |
|
error.errorPrint( |
|
120 |
|
msg="itemUpload: setting values failed", err=err, |
|
121 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
|
122 |
|
data[row['item_sku']] = collections.OrderedDict(zip(column_names, values)) |
|
123 |
|
except KeyError as err: |
|
124 |
|
error.errorPrint(msg="Reading file failed", err=err, |
|
125 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
|
126 |
|
return row['item_sku'] |
|
|
112 |
|
except KeyError as kerr: |
|
113 |
|
error.warnPrint( |
|
114 |
|
msg='itemUpload: key not found in flatfile', err=kerr, |
|
115 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
116 |
|
raise KeyError |
|
117 |
|
except Exception as err: |
|
118 |
|
error.errorPrint( |
|
119 |
|
msg="itemUpload: setting values failed", err=err, |
|
120 |
|
linenumber=sys.exc_info()[2].tb_lineno) |
|
121 |
|
data[row['item_sku']] = collections.OrderedDict(zip(column_names, |
|
122 |
|
values)) |
127 |
123 |
|
|
128 |
124 |
with open(intern['path'], mode='r', encoding=intern['encoding']) as item: |
with open(intern['path'], mode='r', encoding=intern['encoding']) as item: |
129 |
125 |
reader = csv.DictReader(item, delimiter=";") |
reader = csv.DictReader(item, delimiter=";") |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
151 |
147 |
msg=str(f"Barcode part for {row}"), err=err, |
msg=str(f"Barcode part for {row}"), err=err, |
152 |
148 |
linenumber=sys.exc_info()[2].tb_lineno) |
linenumber=sys.exc_info()[2].tb_lineno) |
153 |
149 |
|
|
154 |
|
# Include the amazonsku |
|
155 |
150 |
sku_data = amazon.amazonSkuUpload(flatfile) |
sku_data = amazon.amazonSkuUpload(flatfile) |
156 |
151 |
|
|
157 |
152 |
for row in sku_data: |
for row in sku_data: |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
165 |
160 |
error.errorPrint(msg=str(f"SKU part for {row}"), err=err, |
error.errorPrint(msg=str(f"SKU part for {row}"), err=err, |
166 |
161 |
linenumber=sys.exc_info()[2].tb_lineno) |
linenumber=sys.exc_info()[2].tb_lineno) |
167 |
162 |
|
|
168 |
|
# Sort the dictionary to make sure that the parents are the first variant of each item |
|
169 |
163 |
sorted_data = sortProducts(data) |
sorted_data = sortProducts(data) |
170 |
164 |
|
|
171 |
165 |
barcode.writeCSV(sorted_data, "item", column_names, folder, filename) |
barcode.writeCSV(sorted_data, "item", column_names, folder, filename) |
|
... |
... |
def itemPropertyUpload(flatfile, folder, filename): |
235 |
229 |
|
|
236 |
230 |
barcode.writeCSV(data, "Item_Merkmale", column_names, folder, filename) |
barcode.writeCSV(data, "Item_Merkmale", column_names, folder, filename) |
237 |
231 |
|
|
238 |
|
def getProperties(flatfile): |
|
|
232 |
|
def get_properties(flatfile): |
239 |
233 |
|
|
240 |
234 |
properties = {'length':0, |
properties = {'length':0, |
241 |
235 |
'width':0, |
'width':0, |
|
... |
... |
def getProperties(flatfile): |
274 |
268 |
linenumber=sys.exc_info()[2].tb_lineno) |
linenumber=sys.exc_info()[2].tb_lineno) |
275 |
269 |
sys.exit() |
sys.exit() |
276 |
270 |
except KeyError as err: |
except KeyError as err: |
277 |
|
msg = str(f"getProperties key: {err} not found") |
|
|
271 |
|
msg = str(f"get_properties key: {err} not found") |
278 |
272 |
error.errorPrint(msg=msg, err='', |
error.errorPrint(msg=msg, err='', |
279 |
273 |
linenumber=sys.exc_info()[2].tb_lineno) |
linenumber=sys.exc_info()[2].tb_lineno) |
280 |
274 |
except Exception as err: |
except Exception as err: |
281 |
275 |
error.errorPrint( |
error.errorPrint( |
282 |
|
msg="getProperties setting values failed", err=err, |
|
|
276 |
|
msg="get_properties setting values failed", err=err, |
283 |
277 |
linenumber=sys.exc_info()[2].tb_lineno) |
linenumber=sys.exc_info()[2].tb_lineno) |
284 |
278 |
|
|
285 |
279 |
return properties |
return properties |