-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
124 lines (102 loc) · 5.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
Software Tool to audit Transshipment Sort Out Audit process.
"""
import json
import os
import traceback
import pandas as pd
from colorama import init
from requests import exceptions
from ask_is_strapped import ask_is_strapped
from constants import ask_badge, ask_amz_domain, ask_fc, load_logs, ESCALATION_MSG, COLOR, COLOR_RED, COLOR_GREEN, \
FOLDER
from create_report import create_report, create_bug_report
from get_valid_sites import get_valid_sites
from pallet import Pallet
from version import __title__, __mail__
def main(fc, prices_db, domain, excel_file, badge):
"""
Audit TS Out Process: ask for Pallet Manifest Label (Outer Scannable ID) and for inputs during audit process.
:param fc: str of FC (e.g.: "MXP5")
:param prices_db: dict {asin: {"price": float, "hrv": bool, "gl": str}, ...}
:param domain: str of relevant amazon website's domain (e.g.: "it", "com", "fr", etc. )
:param excel_file: pd Dataframe
:param badge: str of badge bar code (E.g.: "12264605")
:return: None
"""
print(COLOR + "\nInsert Manifest Label (Pallet Outer Scannable ID):\n->", end="")
pallet_code = input()
# remove the next three lines ("else:" included) and deindent the following block to analyze every kind of
# input
if pallet_code[:7] != "PALLET_":
print(COLOR_RED + "Only manifested pallets are accepted. To change this setting, contact an administrator"
"\n(Manifest labels start with 'PALLET_').")
else:
try:
pallet = Pallet(fc, pallet_code, prices_db, domain)
if type(pallet.content) is pd.core.frame.DataFrame:
prices_db = pallet.database # update PRICES_DATABASE
print(COLOR_GREEN + f"\n{pallet_code} has {pallet.priority} priority.\n")
pallet.audit(ESCALATION_MSG)
excel_file = create_report(pallet.content, excel_file, badge) # update SUPER_LOG and overwrite xlsx
print(COLOR + "Report created.")
if pallet.priority != "Not relevant":
ask_is_strapped(pallet.content, pallet_code)
return prices_db, excel_file
except exceptions.RequestException as err:
print(COLOR_RED + f"\nCONNECTION ERROR!!. Please verify your internet connection.\n{err}")
except BaseException as basic_error:
generic_error = traceback.format_exc()
print(COLOR_RED + f"\nFATAL ERROR: {basic_error}.\nPlease signal the bug to {__mail__} and start "
f"again {pallet_code}'s audit.")
create_bug_report(pallet_code, generic_error)
if __name__ == "__main__":
init(autoreset=True) # no need to change back to default color. COMMENT TO REMOVE COLOR
print(COLOR + f"{__title__}\n")
try: # create Folder for reports
os.mkdir(FOLDER)
print(COLOR_RED + f"Folder {FOLDER} not found.")
print(COLOR_GREEN + f"Folder {FOLDER} created.")
except FileExistsError:
pass
while True: # ask Badge, FC, load Excel file with previous Audits and json with prices database
try:
BADGE = ask_badge()
FC = ask_fc(FOLDER)
super_log, prices_database = load_logs() # try to load .xlsx with audits and .json with prices
break
except exceptions.RequestException as e:
print(COLOR_RED + f"\nCONNECTION ERROR!!. Please verify your internet connection.\n{e}")
except BaseException as e:
error = traceback.format_exc()
print(COLOR_RED + f"\nFATAL ERROR: {e}.\nPlease signal the bug to {__mail__} .")
create_bug_report("LOADING CONSTANTS", error)
while True: # ask FC confirmation and checks if FC is valid
try:
with open(FOLDER + "sites.json") as json_sites:
sites_to_domain = json.load(json_sites)
DOMAIN = sites_to_domain[FC]
if DOMAIN is None:
DOMAIN = ask_amz_domain()
break
else:
print(COLOR + f"Do you want to download prices from https://www.amazon.{DOMAIN}/ ?(yes/no)\n->", end="")
confirmation = input().lower()
if confirmation == "yes":
break
elif confirmation == "no":
DOMAIN = ask_amz_domain()
break
else:
print(COLOR_RED + "This answer is not valid. Please insert yes or no.")
except FileNotFoundError:
print(COLOR_RED + "sites.json not found.")
sites_to_domain = get_valid_sites(FOLDER) # get_valid_sites(folder) returns empty dict in case of error
except KeyError:
DOMAIN = ask_amz_domain()
break
while True: # ask for pallet manifest label
updates = main(FC, prices_database, DOMAIN, super_log, BADGE)
if type(updates) is tuple and len(updates) == 2:
prices_database = updates[0] # update PRICES_DATABASE
super_log = updates[1] # update SUPER_LOG and overwrite xlsx