File product_import.py changed (mode: 100644) (index d5ccd2c..27a527d) |
... |
... |
import platform |
5 |
5 |
import os |
import os |
6 |
6 |
import time |
import time |
7 |
7 |
import ntpath |
import ntpath |
8 |
|
from packages.item_upload import itemUpload, WrongEncodingException, check_encoding, check_flatfile, itemPropertyUpload |
|
|
8 |
|
from packages.item_upload import itemUpload, WrongEncodingException, checkEncoding, checkFlatfile, itemPropertyUpload |
9 |
9 |
from packages.barcode import EmptyFieldWarning |
from packages.barcode import EmptyFieldWarning |
10 |
10 |
from packages.amazon_data_upload import featureUpload |
from packages.amazon_data_upload import featureUpload |
11 |
11 |
from packages.log_files import fileNotFoundLog, keyErrorLog, wrongEncodingLog, unboundLocalLog, emptyFieldWarningLog |
from packages.log_files import fileNotFoundLog, keyErrorLog, wrongEncodingLog, unboundLocalLog, emptyFieldWarningLog |
12 |
12 |
from packages.gui.category_chooser import CategoryChooser |
from packages.gui.category_chooser import CategoryChooser |
13 |
13 |
from packages.config import config_creation, config_read, config_write |
from packages.config import config_creation, config_read, config_write |
14 |
14 |
from packages.image_upload import imageUpload |
from packages.image_upload import imageUpload |
|
15 |
|
from packages.category import CategoryConfig |
15 |
16 |
|
|
16 |
17 |
|
|
17 |
18 |
def main(): |
def main(): |
|
... |
... |
def main(): |
22 |
23 |
recent_path = '' |
recent_path = '' |
23 |
24 |
config_path = '' |
config_path = '' |
24 |
25 |
attribute_date = '' |
attribute_date = '' |
|
26 |
|
config = dict() |
25 |
27 |
sheet = {'path':'', 'encoding':''} |
sheet = {'path':'', 'encoding':''} |
26 |
28 |
intern_number = {'path':'', 'encoding':''} |
intern_number = {'path':'', 'encoding':''} |
27 |
29 |
stocklist = {'path':'', 'encoding':''} |
stocklist = {'path':'', 'encoding':''} |
|
... |
... |
def main(): |
29 |
31 |
attributefile = {'path':'', 'encoding':''} |
attributefile = {'path':'', 'encoding':''} |
30 |
32 |
step = int(0) |
step = int(0) |
31 |
33 |
fexc = '' |
fexc = '' |
|
34 |
|
|
|
35 |
|
cat_conf = CategoryConfig() |
|
36 |
|
|
32 |
37 |
# Create a list of step names where every name fits to the index of a step number |
# Create a list of step names where every name fits to the index of a step number |
33 |
38 |
step_name = ['environment-creation', |
step_name = ['environment-creation', |
34 |
39 |
'config-creation', |
'config-creation', |
35 |
40 |
'config-reading', |
'config-reading', |
|
41 |
|
'category-config', |
36 |
42 |
'import-flatfile', |
'import-flatfile', |
37 |
43 |
'GUI', |
'GUI', |
38 |
44 |
'import-internlist', |
'import-internlist', |
|
... |
... |
def main(): |
77 |
83 |
step += 1; |
step += 1; |
78 |
84 |
# CONFIG READING |
# CONFIG READING |
79 |
85 |
# Get the Upload and data folder from the config if possible |
# Get the Upload and data folder from the config if possible |
80 |
|
if(config_read(config_path)['upload_folder']): |
|
81 |
|
upload_folder = config_read(config_path)['upload_folder'] |
|
82 |
|
if(config_read(config_path)['data_folder']): |
|
83 |
|
recent_path = config_read(config_path)['data_folder'] |
|
84 |
|
if(config_read(config_path)['attribute_file']): |
|
85 |
|
attributefile['path'] = config_read(config_path)['attribute_file'] |
|
86 |
|
attributefile = check_encoding(attributefile) |
|
87 |
|
if(config_read(config_path)['file_change_date']): |
|
88 |
|
attribute_date = config_read(config_path)['file_change_date'] |
|
|
86 |
|
config = config_read(config_path) |
|
87 |
|
if(config['upload_folder']): |
|
88 |
|
upload_folder = config['upload_folder'] |
|
89 |
|
if(config['data_folder']): |
|
90 |
|
recent_path = config['data_folder'] |
|
91 |
|
if(config['attribute_file']): |
|
92 |
|
attributefile['path'] = config['attribute_file'] |
|
93 |
|
attributefile = checkEncoding(attributefile) |
|
94 |
|
if(config['file_change_date']): |
|
95 |
|
attribute_date = config['file_change_date'] |
|
96 |
|
if(config['category_config']): |
|
97 |
|
cat_conf.path['path'] = config['category_config'] |
|
98 |
|
cat_conf.path = checkEncoding(cat_conf.path) |
|
99 |
|
|
|
100 |
|
# Category Config |
|
101 |
|
if(not(cat_conf.path['path'])): |
|
102 |
|
if(not(cat_conf.findConfig(os.path.dirname( |
|
103 |
|
os.path.abspath(__file__))))): |
|
104 |
|
print('no category config found\n') |
|
105 |
|
print('Press Enter to continue...') |
|
106 |
|
input() |
|
107 |
|
sys.exit() |
|
108 |
|
cat_conf.readConfig() |
|
109 |
|
|
89 |
110 |
if(not(recent_path)): |
if(not(recent_path)): |
90 |
111 |
recent_path = tkinter.filedialog.askdirectory(initialdir=initial_directory, |
recent_path = tkinter.filedialog.askdirectory(initialdir=initial_directory, |
91 |
112 |
title="Choose a folder from where to upload") |
title="Choose a folder from where to upload") |
|
... |
... |
def main(): |
96 |
117 |
attributefile['path'] = askopenfilename(initialdir=recent_path, |
attributefile['path'] = askopenfilename(initialdir=recent_path, |
97 |
118 |
title="Color Attributes from PlentyMarkets", |
title="Color Attributes from PlentyMarkets", |
98 |
119 |
filetypes=[ ("csv files", "*.csv") ]) |
filetypes=[ ("csv files", "*.csv") ]) |
99 |
|
attributefile = check_encoding(attributefile) |
|
|
120 |
|
attributefile = checkEncoding(attributefile) |
100 |
121 |
|
|
101 |
122 |
# Import Flatfile |
# Import Flatfile |
102 |
123 |
step += 1 |
step += 1 |
|
... |
... |
def main(): |
104 |
125 |
title="Amazon Flatfile as .csv", |
title="Amazon Flatfile as .csv", |
105 |
126 |
filetypes=[ ("csv files", "*.csv") ]) |
filetypes=[ ("csv files", "*.csv") ]) |
106 |
127 |
|
|
107 |
|
sheet = check_encoding(sheet) |
|
|
128 |
|
sheet = checkEncoding(sheet) |
108 |
129 |
|
|
109 |
130 |
# Check if the file was loaded properly and got the correct format |
# Check if the file was loaded properly and got the correct format |
110 |
131 |
try: |
try: |
111 |
|
if(not( check_flatfile(sheet) )): |
|
|
132 |
|
if(not( checkFlatfile(sheet) )): |
112 |
133 |
print('Please fix the flatfile and try again.\n') |
print('Please fix the flatfile and try again.\n') |
113 |
134 |
print('Press Enter to continue...') |
print('Press Enter to continue...') |
114 |
135 |
input() |
input() |
|
... |
... |
def main(): |
122 |
143 |
step += 1; |
step += 1; |
123 |
144 |
# GUI |
# GUI |
124 |
145 |
# Ask the user for input inside a gui asking for categories and name |
# Ask the user for input inside a gui asking for categories and name |
125 |
|
cchooser = CategoryChooser(None, upload_folder, sheet, attributefile, attribute_date) |
|
|
146 |
|
cchooser = CategoryChooser(None, cat_conf.id_list, upload_folder, sheet, attributefile, |
|
147 |
|
attribute_date) |
126 |
148 |
cchooser.title("Choose the category and name") |
cchooser.title("Choose the category and name") |
127 |
149 |
LOOP_ACTIVE = True |
LOOP_ACTIVE = True |
128 |
150 |
while (LOOP_ACTIVE): |
while (LOOP_ACTIVE): |
129 |
151 |
if(cchooser): |
if(cchooser): |
130 |
152 |
cchooser.update() |
cchooser.update() |
131 |
|
time.sleep(0.3) |
|
|
153 |
|
time.sleep(0.1) |
132 |
154 |
if(cchooser.data['name'] and cchooser.data['categories'] and\ |
if(cchooser.data['name'] and cchooser.data['categories'] and\ |
133 |
155 |
cchooser.data['marking']): |
cchooser.data['marking']): |
134 |
156 |
LOOP_ACTIVE = False |
LOOP_ACTIVE = False |
|
... |
... |
def main(): |
175 |
197 |
|
|
176 |
198 |
if(user_data): |
if(user_data): |
177 |
199 |
# Check if there is already a log folder within the upload folder |
# Check if there is already a log folder within the upload folder |
178 |
|
print(upload_folder) |
|
179 |
200 |
if( not(os.path.exists(os.path.join(upload_folder, 'log'))) ): |
if( not(os.path.exists(os.path.join(upload_folder, 'log'))) ): |
180 |
201 |
log_folder = os.path.join(upload_folder, 'log') |
log_folder = os.path.join(upload_folder, 'log') |
181 |
202 |
os.makedirs(log_folder) |
os.makedirs(log_folder) |
|
... |
... |
def main(): |
187 |
208 |
title="The Intern Numbers as .csv", |
title="The Intern Numbers as .csv", |
188 |
209 |
filetypes=[ ("csv files", "*.csv") ]) |
filetypes=[ ("csv files", "*.csv") ]) |
189 |
210 |
|
|
190 |
|
intern_number = check_encoding(intern_number) |
|
|
211 |
|
intern_number = checkEncoding(intern_number) |
191 |
212 |
|
|
192 |
213 |
step += 1; |
step += 1; |
193 |
214 |
try: |
try: |
|
... |
... |
def main(): |
195 |
216 |
title="The Stockreport from Amazon as .csv", |
title="The Stockreport from Amazon as .csv", |
196 |
217 |
filetypes=[ ("csv files", "*.csv") ]) |
filetypes=[ ("csv files", "*.csv") ]) |
197 |
218 |
|
|
198 |
|
stocklist = check_encoding(stocklist) |
|
|
219 |
|
stocklist = checkEncoding(stocklist) |
199 |
220 |
except OSError as fexc: |
except OSError as fexc: |
200 |
221 |
fileNotFoundLog( |
fileNotFoundLog( |
201 |
222 |
log_path=log_folder, step_number=step, |
log_path=log_folder, step_number=step, |
|
... |
... |
def main(): |
295 |
316 |
title="Export File from Plentymarkets", |
title="Export File from Plentymarkets", |
296 |
317 |
filetypes=[ ("csv files", "*.csv") ]) |
filetypes=[ ("csv files", "*.csv") ]) |
297 |
318 |
|
|
298 |
|
plenty_export = check_encoding(plenty_export) |
|
|
319 |
|
plenty_export = checkEncoding(plenty_export) |
299 |
320 |
|
|
300 |
321 |
step += 1 |
step += 1 |
301 |
322 |
imageUpload(flatfile=sheet, |
imageUpload(flatfile=sheet, |