File packages/amazon.py renamed from packages/amazon_data_upload.py (similarity 56%) (mode: 100644) (index 249c228..3a5f2ad) |
1 |
1 |
import csv |
import csv |
|
2 |
|
import pandas |
2 |
3 |
from os.path import isfile |
from os.path import isfile |
3 |
4 |
from packages import barcode |
from packages import barcode |
4 |
5 |
try: |
try: |
|
... |
... |
def amazonSkuUpload(flatfile): |
29 |
30 |
return Data |
return Data |
30 |
31 |
|
|
31 |
32 |
|
|
32 |
|
def amazonDataUpload(flatfile): |
|
33 |
|
|
|
34 |
|
column_names = ['ItemAmazonProductType', |
|
35 |
|
'ItemAmazonFBA', |
|
36 |
|
'ItemShippingWithAmazonFBA'] |
|
37 |
|
|
|
38 |
|
Data = SortedDict() |
|
39 |
|
|
|
40 |
|
with open(flatfile['path'], mode='r', encoding=flatfile['encoding']) as item: |
|
41 |
|
reader = csv.DictReader(item, delimiter=";") |
|
42 |
|
|
|
43 |
|
type_id = { |
|
44 |
|
'accessory': 28, |
|
45 |
|
'shirt': 13, |
|
46 |
|
'pants': 15, |
|
47 |
|
'dress': 18, |
|
48 |
|
'outerwear': 21, |
|
49 |
|
'bag': 27, |
|
50 |
|
'furnitureanddecor': 4, |
|
51 |
|
'bedandbath': 3, |
|
52 |
|
'swimwear': 30 |
|
53 |
|
} |
|
54 |
|
|
|
55 |
|
values = '' |
|
56 |
|
product_type = '' |
|
57 |
|
|
|
58 |
|
for row in reader: |
|
59 |
|
# go through the variations until the values are filled |
|
60 |
|
if(row['feed_product_type'].lower() in [*type_id]): |
|
61 |
|
for key in type_id: |
|
62 |
|
if(row['feed_product_type'].lower() == key): |
|
63 |
|
product_type = type_id[key] |
|
64 |
|
else: |
|
65 |
|
print("ERROR @ product type in AmazonData: {0} not in {1}" |
|
66 |
|
.format(row['feed_product_type'], |
|
67 |
|
",".join([*type_id]))) |
|
68 |
|
|
|
69 |
|
if(not(product_type) and not(row['feed_product_type'])): |
|
70 |
|
raise barcode.EmptyFieldWarning('product_type') |
|
71 |
|
|
|
72 |
|
values = [product_type, '1', '1'] |
|
73 |
|
|
|
74 |
|
Data[row['item_sku']] = SortedDict(zip(column_names, values)) |
|
75 |
|
|
|
76 |
|
return Data |
|
77 |
|
|
|
|
33 |
|
def get_producttype_id(source, sku): |
|
34 |
|
""" |
|
35 |
|
Parameter: |
|
36 |
|
source [Dictionary] => dictionary of the flatfile |
|
37 |
|
with path and encoding |
|
38 |
|
sku [String] => String of the product sku |
|
39 |
|
|
|
40 |
|
Description: |
|
41 |
|
Search for a matching term in mapping list of valid |
|
42 |
|
amazon producttype names and their ID. |
|
43 |
|
|
|
44 |
|
Return: |
|
45 |
|
[Integer] |
|
46 |
|
value from type_id on success |
|
47 |
|
0 on failure |
|
48 |
|
""" |
|
49 |
|
type_id = { |
|
50 |
|
'accessory': 28, |
|
51 |
|
'shirt': 13, |
|
52 |
|
'pants': 15, |
|
53 |
|
'dress': 18, |
|
54 |
|
'outerwear': 21, |
|
55 |
|
'bag': 27, |
|
56 |
|
'furnitureanddecor': 4, |
|
57 |
|
'bedandbath': 3, |
|
58 |
|
'swimwear': 30 |
|
59 |
|
} |
|
60 |
|
|
|
61 |
|
df = pandas.read_csv(source['path'], |
|
62 |
|
sep=';', |
|
63 |
|
encoding=source['encoding']) |
|
64 |
|
|
|
65 |
|
sku_df = df[df['item_sku'] == sku] |
|
66 |
|
if len(sku_df.index) == 0: |
|
67 |
|
error.warnPrint(msg=str(f"{sku} not found in flatfile"), err='', |
|
68 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
69 |
|
return 0 |
|
70 |
|
|
|
71 |
|
if sku_df.filter(like='product_type', axis=1).empty: |
|
72 |
|
msg=str("wrong header: ..{0} requires a product_type column" |
|
73 |
|
.format(source['path'][-21:])) |
|
74 |
|
error.warnPrint( |
|
75 |
|
msg=msg, err='', |
|
76 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
77 |
|
return 0 |
|
78 |
|
|
|
79 |
|
value = sku_df.filter(like='product_type', axis=1)\ |
|
80 |
|
.to_string(na_rep='', index=False, header=False)\ |
|
81 |
|
.lower().strip(' ') |
|
82 |
|
|
|
83 |
|
if not value: |
|
84 |
|
return 0 |
|
85 |
|
|
|
86 |
|
if value in type_id.keys(): |
|
87 |
|
return type_id[value] |
78 |
88 |
|
|
79 |
89 |
def featureUpload(flatfile, features, folder, filename): |
def featureUpload(flatfile, features, folder, filename): |
80 |
90 |
|
|
File packages/item_upload.py changed (mode: 100644) (index a9c9d5b..b195ce5) |
... |
... |
import collections |
5 |
5 |
import inspect |
import inspect |
6 |
6 |
import chardet |
import chardet |
7 |
7 |
import os |
import os |
8 |
|
from packages import barcode, amazon_data_upload, price, error |
|
|
8 |
|
from packages import barcode, amazon, price, error |
9 |
9 |
|
|
10 |
10 |
|
|
11 |
11 |
class WrongEncodingException(Exception): |
class WrongEncodingException(Exception): |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
27 |
27 |
'EAN_Barcode', 'FNSKU_Barcode', |
'EAN_Barcode', 'FNSKU_Barcode', |
28 |
28 |
'marketid', 'accountid', |
'marketid', 'accountid', |
29 |
29 |
'amazon_sku', 'amazon_parentsku', |
'amazon_sku', 'amazon_parentsku', |
30 |
|
'amazon-producttype', 'fba-enabled', 'fba-shipping', |
|
|
30 |
|
'amazon-producttype', |
31 |
31 |
'price', 'ASIN-countrycode', 'ASIN-type', 'ASIN-value', |
'price', 'ASIN-countrycode', 'ASIN-type', 'ASIN-value', |
32 |
32 |
'Item-Flag-1' |
'Item-Flag-1' |
33 |
33 |
] |
] |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
113 |
113 |
'', '', # barcode |
'', '', # barcode |
114 |
114 |
'', '', # market & accout id amazonsku |
'', '', # market & accout id amazonsku |
115 |
115 |
'', '', # sku & parentsku amazonsku |
'', '', # sku & parentsku amazonsku |
116 |
|
'', '', '', # producttype & fba amazon |
|
|
116 |
|
amazon.get_producttype_id(source=flatfile, |
|
117 |
|
sku=row['item_sku']), |
117 |
118 |
item_price, # prices |
item_price, # prices |
118 |
119 |
'', '', '', #asin |
'', '', '', #asin |
119 |
120 |
input_data['marking'] |
input_data['marking'] |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
160 |
161 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
161 |
162 |
|
|
162 |
163 |
# Include the amazonsku |
# Include the amazonsku |
163 |
|
sku_data = amazon_data_upload.amazonSkuUpload(flatfile) |
|
|
164 |
|
sku_data = amazon.amazonSkuUpload(flatfile) |
164 |
165 |
|
|
165 |
166 |
for row in sku_data: |
for row in sku_data: |
166 |
167 |
try: |
try: |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
173 |
174 |
error.errorPrint("SKU part for "+row, err, |
error.errorPrint("SKU part for "+row, err, |
174 |
175 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
175 |
176 |
|
|
176 |
|
# Include the amazonsku |
|
177 |
|
ama_data = amazon_data_upload.amazonDataUpload(flatfile) |
|
178 |
|
|
|
179 |
|
for row in ama_data: |
|
180 |
|
try: |
|
181 |
|
if row in list(data.keys()): |
|
182 |
|
data[row]['amazon-producttype'] = ama_data[row]['ItemAmazonProductType'] |
|
183 |
|
data[row]['fba-enabled'] = ama_data[row]['ItemAmazonFBA'] |
|
184 |
|
data[row]['fba-shipping'] = ama_data[row]['ItemShippingWithAmazonFBA'] |
|
185 |
|
except Exception as err: |
|
186 |
|
error.errorPrint("Amazondata part for "+row, err, |
|
187 |
|
sys.exc_info()[2].tb_lineno) |
|
188 |
|
|
|
189 |
177 |
# 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 |
190 |
178 |
sorted_data = sortProducts(data) |
sorted_data = sortProducts(data) |
191 |
179 |
|
|
File product_import.py changed (mode: 100644) (index 5256fe6..13f165e) |
1 |
|
import tkinter |
|
2 |
|
from tkinter.filedialog import askopenfilename |
|
3 |
|
import sys |
|
4 |
|
import platform |
|
5 |
|
import os |
|
6 |
1 |
import time |
import time |
7 |
2 |
import ntpath |
import ntpath |
8 |
3 |
import re |
import re |
9 |
4 |
import datetime |
import datetime |
|
5 |
|
import tkinter |
|
6 |
|
from tkinter.filedialog import askopenfilename |
|
7 |
|
import os |
|
8 |
|
import sys |
|
9 |
|
import platform |
10 |
10 |
try: |
try: |
11 |
11 |
import configparser |
import configparser |
12 |
12 |
except ImportError: |
except ImportError: |
|
... |
... |
from packages.item_upload import ( |
16 |
16 |
itemUpload, WrongEncodingException, checkEncoding, |
itemUpload, WrongEncodingException, checkEncoding, |
17 |
17 |
checkFlatfile, itemPropertyUpload) |
checkFlatfile, itemPropertyUpload) |
18 |
18 |
from packages.barcode import EmptyFieldWarning |
from packages.barcode import EmptyFieldWarning |
19 |
|
from packages.amazon_data_upload import featureUpload |
|
|
19 |
|
from packages.amazon import featureUpload |
20 |
20 |
from packages.log_files import ( |
from packages.log_files import ( |
21 |
21 |
fileNotFoundLog, keyErrorLog, wrongEncodingLog, |
fileNotFoundLog, keyErrorLog, wrongEncodingLog, |
22 |
22 |
unboundLocalLog, emptyFieldWarningLog) |
unboundLocalLog, emptyFieldWarningLog) |