File packages/item_upload.py changed (mode: 100644) (index c5bcfb3..581c241) |
... |
... |
import re |
4 |
4 |
import collections |
import collections |
5 |
5 |
import inspect |
import inspect |
6 |
6 |
import chardet |
import chardet |
7 |
|
from packages import barcode, amazon_data_upload, price_upload, error |
|
|
7 |
|
import os |
|
8 |
|
from packages import barcode, amazon_data_upload, price, error |
8 |
9 |
|
|
9 |
10 |
|
|
10 |
11 |
class WrongEncodingException(Exception): |
class WrongEncodingException(Exception): |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
32 |
33 |
'market-active-amafbager', 'marketid', 'accountid', |
'market-active-amafbager', 'marketid', 'accountid', |
33 |
34 |
'amazon_sku', 'amazon_parentsku', |
'amazon_sku', 'amazon_parentsku', |
34 |
35 |
'amazon-producttype', 'fba-enabled', 'fba-shipping', |
'amazon-producttype', 'fba-enabled', 'fba-shipping', |
35 |
|
'price-price', 'ebay-price', 'amazon-price', |
|
36 |
|
'webshop-price', 'etsy-price', 'cdiscount-price', |
|
37 |
|
'ASIN-countrycode', 'ASIN-type', 'ASIN-value', |
|
|
36 |
|
'price', 'ASIN-countrycode', 'ASIN-type', 'ASIN-value', |
38 |
37 |
'Item-Flag-1' |
'Item-Flag-1' |
39 |
38 |
] |
] |
40 |
39 |
|
|
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
44 |
43 |
barcode_data = {} |
barcode_data = {} |
45 |
44 |
is_parent = False |
is_parent = False |
46 |
45 |
position = 0 |
position = 0 |
|
46 |
|
item_price = 0 |
47 |
47 |
|
|
48 |
48 |
# Get sets of all colors and sizes for each parent |
# Get sets of all colors and sizes for each parent |
49 |
49 |
# to find if there are some with only one attribute value for all childs |
# to find if there are some with only one attribute value for all childs |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
70 |
70 |
error.warnPrint("Generic Keywords are empty!", |
error.warnPrint("Generic Keywords are empty!", |
71 |
71 |
inspect.currentframe().f_back.f_lineno) |
inspect.currentframe().f_back.f_lineno) |
72 |
72 |
|
|
|
73 |
|
item_price = row['standard_price'] |
|
74 |
|
if not item_price and row['parent_child'] == 'parent': |
|
75 |
|
item_price=price.find_price(flatfile, row['item_sku']) |
|
76 |
|
if item_price == -1: |
|
77 |
|
if os.name == 'nt': |
|
78 |
|
print("press ENTER to continue..") |
|
79 |
|
input() |
|
80 |
|
exit(1) |
|
81 |
|
if item_price == '': |
|
82 |
|
error.warnPrint( |
|
83 |
|
msg=str(f"{row['item_sku']}, has no price"), err='', |
|
84 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
85 |
|
|
|
86 |
|
|
73 |
87 |
try: |
try: |
74 |
88 |
attributes = '' |
attributes = '' |
75 |
89 |
if row['parent_child'] == 'parent': |
if row['parent_child'] == 'parent': |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
110 |
124 |
'', '', # market & accout id amazonsku |
'', '', # market & accout id amazonsku |
111 |
125 |
'', '', # sku & parentsku amazonsku |
'', '', # sku & parentsku amazonsku |
112 |
126 |
'', '', '', # producttype & fba amazon |
'', '', '', # producttype & fba amazon |
113 |
|
'', '', '', '', '', '', # prices |
|
|
127 |
|
item_price, # prices |
114 |
128 |
'', '', '', #asin |
'', '', '', #asin |
115 |
129 |
input_data['marking'] |
input_data['marking'] |
116 |
130 |
] |
] |
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
182 |
196 |
error.errorPrint("Amazondata part for "+row, err, |
error.errorPrint("Amazondata part for "+row, err, |
183 |
197 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
184 |
198 |
|
|
185 |
|
# Include the price |
|
186 |
|
price_data = price_upload.priceUpload(flatfile) |
|
187 |
|
|
|
188 |
|
for row in price_data: |
|
189 |
|
try: |
|
190 |
|
if row in list(data.keys()): |
|
191 |
|
data[row]['price-price'] = price_data[row]['price'] |
|
192 |
|
data[row]['ebay-price'] = price_data[row]['ebay'] |
|
193 |
|
data[row]['amazon-price'] = price_data[row]['amazon'] |
|
194 |
|
data[row]['webshop-price'] = price_data[row]['webshop'] |
|
195 |
|
data[row]['etsy-price'] = price_data[row]['etsy'] |
|
196 |
|
except Exception as err: |
|
197 |
|
error.errorPrint("Price part for "+row, err, |
|
198 |
|
sys.exc_info()[2].tb_lineno) |
|
199 |
|
|
|
200 |
199 |
# 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 |
201 |
200 |
sorted_data = sortProducts(data) |
sorted_data = sortProducts(data) |
202 |
201 |
|
|
|
... |
... |
def itemUpload(flatfile, intern, stocklist, folder, input_data, filename): |
204 |
203 |
except UnicodeDecodeError as err: |
except UnicodeDecodeError as err: |
205 |
204 |
error.errorPrint("decoding problem", err, |
error.errorPrint("decoding problem", err, |
206 |
205 |
sys.exc_info()[2].tb_lineno) |
sys.exc_info()[2].tb_lineno) |
207 |
|
print("press ENTER to continue..") |
|
208 |
|
input() |
|
209 |
|
sys.exit() |
|
|
206 |
|
if os.name == 'nt': |
|
207 |
|
print("press ENTER to continue..") |
|
208 |
|
input() |
|
209 |
|
exit(1) |
210 |
210 |
|
|
211 |
211 |
def itemPropertyUpload(flatfile, folder, filename): |
def itemPropertyUpload(flatfile, folder, filename): |
212 |
212 |
|
|
|
... |
... |
def getVariationId(exportfile, sku): |
494 |
494 |
except Exception as err: |
except Exception as err: |
495 |
495 |
error.errorPrint("Looking for irregularities in getVariationId", |
error.errorPrint("Looking for irregularities in getVariationId", |
496 |
496 |
err, sys.exc_info()[2].tb_lineno) |
err, sys.exc_info()[2].tb_lineno) |
497 |
|
print("press ENTER to continue...") |
|
498 |
|
input() |
|
|
497 |
|
if os.name == 'nt': |
|
498 |
|
print("press ENTER to continue...") |
|
499 |
|
input() |
|
500 |
|
exit(1) |
499 |
501 |
if not variationid: |
if not variationid: |
500 |
502 |
error.warnPrint(msg="No Variation ID found for "+sku, |
error.warnPrint(msg="No Variation ID found for "+sku, |
501 |
503 |
linenumber=inspect.currentframe().f_back.f_lineno) |
linenumber=inspect.currentframe().f_back.f_lineno) |
File packages/price.py added (mode: 100644) (index 0000000..46e0edf) |
|
1 |
|
""" |
|
2 |
|
Author: Sebastian Fricke |
|
3 |
|
License: GPLv3 |
|
4 |
|
Date: 2020-04-27 |
|
5 |
|
|
|
6 |
|
Functions for working with the price field of the Amazon Flatfile |
|
7 |
|
""" |
|
8 |
|
|
|
9 |
|
import inspect |
|
10 |
|
import pandas |
|
11 |
|
from packages import error |
|
12 |
|
|
|
13 |
|
|
|
14 |
|
def find_price(flatfile, parent): |
|
15 |
|
""" |
|
16 |
|
Parameter: |
|
17 |
|
flatfile [Dictionary] => path and encoding as strings |
|
18 |
|
of the flatfile |
|
19 |
|
parent [String] => Name of the parent that requires a price |
|
20 |
|
|
|
21 |
|
Description: |
|
22 |
|
Transfer the variation price to the parent price if the |
|
23 |
|
parent doesn't own a price |
|
24 |
|
|
|
25 |
|
Return: |
|
26 |
|
result [float] => price |
|
27 |
|
0 = No variation has a price |
|
28 |
|
-1 = Error |
|
29 |
|
""" |
|
30 |
|
|
|
31 |
|
df = pandas.read_csv(flatfile['path'], |
|
32 |
|
encoding=flatfile['encoding'], |
|
33 |
|
sep=';') |
|
34 |
|
|
|
35 |
|
if df.empty: |
|
36 |
|
error.errorPrint( |
|
37 |
|
msg=str(f"Couldn't read {flatfile['path']}"), err='', |
|
38 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
39 |
|
return -1 |
|
40 |
|
|
|
41 |
|
variation = df[df['parent_sku'] == parent] |
|
42 |
|
if variation.empty: |
|
43 |
|
error.errorPrint( |
|
44 |
|
msg=str(f"No variation for {parent} in {flatfile['path']}"), |
|
45 |
|
err='', linenumber=inspect.currentframe().f_back.f_lineno) |
|
46 |
|
return -1 |
|
47 |
|
|
|
48 |
|
with_price = variation['standard_price'].notnull() |
|
49 |
|
if variation[with_price].empty: |
|
50 |
|
error.warnPrint( |
|
51 |
|
msg=str(f"No variation of {parent} has a price"), err='', |
|
52 |
|
linenumber=inspect.currentframe().f_back.f_lineno) |
|
53 |
|
return 0 |
|
54 |
|
|
|
55 |
|
|
|
56 |
|
variation = variation.astype({'standard_price':float}) |
|
57 |
|
result = variation['standard_price'].values.max() |
|
58 |
|
|
|
59 |
|
return result |