File packages/item_upload.py changed (mode: 100644) (index fc462e4..59433c1) |
... |
... |
import csv |
2 |
2 |
import sys |
import sys |
3 |
3 |
import re |
import re |
4 |
4 |
import chardet |
import chardet |
|
5 |
|
import collections |
5 |
6 |
from os.path import isfile |
from os.path import isfile |
6 |
7 |
from sys import exit |
from sys import exit |
7 |
8 |
from packages import barcode, amazon_data_upload, price_upload, image_upload |
from packages import barcode, amazon_data_upload, price_upload, image_upload |
|
... |
... |
def get_variationid(exportfile, sku): |
66 |
67 |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
67 |
68 |
# The column headers for the output file as expected from the |
# The column headers for the output file as expected from the |
68 |
69 |
# plentymarkets dataformat |
# plentymarkets dataformat |
69 |
|
column_names = ['ItemID', 'Parent-SKU', 'SKU', |
|
|
70 |
|
column_names = ['Parent-SKU', 'SKU', |
70 |
71 |
'Length', 'Width', |
'Length', 'Width', |
71 |
72 |
'Height', 'Weight', |
'Height', 'Weight', |
72 |
73 |
'Name', 'MainWarehouse', |
'Name', 'MainWarehouse', |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
74 |
75 |
'ItemOriginCountry', 'ItemTextKeywords', |
'ItemOriginCountry', 'ItemTextKeywords', |
75 |
76 |
'ItemProducer', 'ItemProducerID', |
'ItemProducer', 'ItemProducerID', |
76 |
77 |
'ItemTextName', 'ItemTextDescription', |
'ItemTextName', 'ItemTextDescription', |
77 |
|
'ExternalID', 'VariationActive', |
|
|
78 |
|
'ExternalID', |
78 |
79 |
'VariationAvailability', 'Category-IDs', |
'VariationAvailability', 'Category-IDs', |
79 |
80 |
'Standard-Category', 'Standard-Category-Webshop', |
'Standard-Category', 'Standard-Category-Webshop', |
80 |
81 |
'Mandant-Active', 'Webshop-Active', |
'Mandant-Active', 'Webshop-Active', |
81 |
82 |
'EAN_Barcode', 'FNSKU_Barcode', |
'EAN_Barcode', 'FNSKU_Barcode', |
82 |
83 |
'market-active-shop', 'market-active-ebay', |
'market-active-shop', 'market-active-ebay', |
83 |
84 |
'market-active-ebayger', 'market-active-amafba', |
'market-active-ebayger', 'market-active-amafba', |
84 |
|
'market-active-amafbager', 'market-active-webapi', |
|
85 |
|
'marketid', 'accountid', |
|
|
85 |
|
'market-active-amafbager', 'marketid', 'accountid', |
86 |
86 |
'amazon_sku', 'amazon_parentsku', |
'amazon_sku', 'amazon_parentsku', |
87 |
87 |
'amazon-producttype', 'fba-enabled', 'fba-shipping', |
'amazon-producttype', 'fba-enabled', 'fba-shipping', |
88 |
88 |
'price-price', 'ebay-price', 'amazon-price', |
'price-price', 'ebay-price', 'amazon-price', |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
95 |
95 |
# Unpack File and scrap data |
# Unpack File and scrap data |
96 |
96 |
# INPUT |
# INPUT |
97 |
97 |
# -------------------------------------------------------------- |
# -------------------------------------------------------------- |
98 |
|
Data = SortedDict() |
|
|
98 |
|
Data = dict() |
|
99 |
|
sorted_Data = collections.OrderedDict() |
99 |
100 |
package_properties = {} |
package_properties = {} |
100 |
101 |
barcode_data = {} |
barcode_data = {} |
101 |
102 |
|
|
|
... |
... |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
136 |
137 |
|
|
137 |
138 |
try: |
try: |
138 |
139 |
values = [ |
values = [ |
139 |
|
'', row['parent_sku'], row['item_sku'], |
|
|
140 |
|
row['parent_sku'], row['item_sku'], |
140 |
141 |
package_properties[ 'length' ] * 10, package_properties[ 'width' ] * 10, |
package_properties[ 'length' ] * 10, package_properties[ 'width' ] * 10, |
141 |
142 |
package_properties[ 'height' ] * 10, package_properties[ 'weight' ], |
package_properties[ 'height' ] * 10, package_properties[ 'weight' ], |
142 |
143 |
row['item_name'], '104', |
row['item_name'], '104', |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
144 |
145 |
'62', keywords, |
'62', keywords, |
145 |
146 |
row['brand_name'].upper(), '3', |
row['brand_name'].upper(), '3', |
146 |
147 |
input_data['name'], row['product_description'], |
input_data['name'], row['product_description'], |
147 |
|
'', 'true', # externalID & active |
|
|
148 |
|
'', # externalID |
148 |
149 |
'3', input_data['categories'], |
'3', input_data['categories'], |
149 |
150 |
input_data['categories'][0:2], input_data['categories'][0:2], |
input_data['categories'][0:2], input_data['categories'][0:2], |
150 |
151 |
'Y', 'Y', # mandant |
'Y', 'Y', # mandant |
151 |
152 |
'', '', # barcode |
'', '', # barcode |
152 |
153 |
'Y', 'Y', # marketconnection |
'Y', 'Y', # marketconnection |
153 |
154 |
'Y', 'Y', # marketconnection |
'Y', 'Y', # marketconnection |
154 |
|
'Y', 'Y', # marketconnection |
|
|
155 |
|
'Y', # marketconnection |
155 |
156 |
'', '', # market & accout id amazonsku |
'', '', # market & accout id amazonsku |
156 |
157 |
'', '', # sku & parentsku amazonsku |
'', '', # sku & parentsku amazonsku |
157 |
158 |
'', '', '',# producttype & fba amazon |
'', '', '',# producttype & fba amazon |
158 |
159 |
'','','','','','',# prices |
'','','','','','',# prices |
159 |
160 |
'', '', '', #asin |
'', '', '', #asin |
160 |
|
item_flag |
|
|
161 |
|
item_flag # item flag 1 the sign of the item status |
161 |
162 |
] |
] |
162 |
163 |
|
|
163 |
164 |
except KeyError: |
except KeyError: |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, attributefile, folder, input_data): |
233 |
234 |
except Exception as err: |
except Exception as err: |
234 |
235 |
print("ERROR @ Price Part for {0}.\n{1}.\n".format(row, err)) |
print("ERROR @ Price Part for {0}.\n{1}.\n".format(row, err)) |
235 |
236 |
|
|
236 |
|
# Write Data into new CSV for Upload |
|
237 |
|
# OUTPUT |
|
238 |
|
# -------------------------------------------------------------- |
|
|
237 |
|
# Write Data into new CSV for Upload |
|
238 |
|
# OUTPUT |
|
239 |
|
# -------------------------------------------------------------- |
|
240 |
|
|
|
241 |
|
# Sort the dictionary to make sure that the parents are the first variant of each item |
|
242 |
|
print("Sort Products") |
|
243 |
|
sorted_Data = sort_Products(Data) |
239 |
244 |
|
|
240 |
|
barcode.writeCSV(Data, "item", column_names, folder) |
|
|
245 |
|
barcode.writeCSV(sorted_Data, "item", column_names, folder) |
241 |
246 |
except UnicodeDecodeError as err: |
except UnicodeDecodeError as err: |
242 |
247 |
print("Decode Error at line: {0}, err: {1}".format(sys.exc_info()[2].tb_lineno, err)) |
print("Decode Error at line: {0}, err: {1}".format(sys.exc_info()[2].tb_lineno, err)) |
243 |
248 |
print("press ENTER to continue..") |
print("press ENTER to continue..") |
|
... |
... |
def itemPropertyUpload(flatfile, folder): |
303 |
308 |
|
|
304 |
309 |
properties[row['item_sku']] = dict(zip(property_names, values)) |
properties[row['item_sku']] = dict(zip(property_names, values)) |
305 |
310 |
|
|
306 |
|
column_names = ['SKU', 'ID-property', 'Value', 'Lang'] |
|
|
311 |
|
column_names = ['SKU', 'ID-property', 'Value', 'Lang', 'Active'] |
307 |
312 |
Data = {} |
Data = {} |
308 |
313 |
for index, row in enumerate( properties ): |
for index, row in enumerate( properties ): |
309 |
314 |
for prop in property_id: |
for prop in property_id: |
|
... |
... |
def get_properties(flatfile): |
318 |
323 |
properties = {'length':0, |
properties = {'length':0, |
319 |
324 |
'width':0, |
'width':0, |
320 |
325 |
'height':0, |
'height':0, |
321 |
|
'weight':0} |
|
|
326 |
|
'weight':0, |
|
327 |
|
'1'} |
322 |
328 |
|
|
323 |
329 |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
324 |
330 |
reader = csv.DictReader(item, delimiter=";") |
reader = csv.DictReader(item, delimiter=";") |
|
... |
... |
def find_similar_attr(flatfile): |
389 |
395 |
Data[row['parent_sku']]['size'].add(row['size_name']) |
Data[row['parent_sku']]['size'].add(row['size_name']) |
390 |
396 |
|
|
391 |
397 |
return Data |
return Data |
|
398 |
|
|
|
399 |
|
def sort_Products(dataset): |
|
400 |
|
item_list = dataset.items() |
|
401 |
|
new_dict = collections.OrderedDict() |
|
402 |
|
parent_dict = collections.OrderedDict() |
|
403 |
|
child_dict = collections.OrderedDict() |
|
404 |
|
position_of_parent = 0 |
|
405 |
|
|
|
406 |
|
# Go through the items of the dataset |
|
407 |
|
for item in item_list: |
|
408 |
|
# When there is no entry in 'Parent-SKU' the item has to be a parent |
|
409 |
|
if(not(item[0] in [* new_dict ])): |
|
410 |
|
if(not(item[1]['Parent-SKU'])): |
|
411 |
|
# add the parent to the new dict |
|
412 |
|
new_dict[item[0]] = item[1] |
|
413 |
|
# get all the children and update the itemlist without them |
|
414 |
|
child_dict = search_child(item_list, item[0]) |
|
415 |
|
# add each child to the new dict after the parent |
|
416 |
|
for child in child_dict: |
|
417 |
|
new_dict[child] = child_dict[child] |
|
418 |
|
|
|
419 |
|
return new_dict |
|
420 |
|
|
|
421 |
|
def search_child(item_list, parent): |
|
422 |
|
child_dict = collections.OrderedDict() |
|
423 |
|
|
|
424 |
|
for item in item_list: |
|
425 |
|
if(item[1]['Parent-SKU'] == parent): |
|
426 |
|
child_dict[item[0]] = item[1] |
|
427 |
|
|
|
428 |
|
return child_dict |