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