-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
126 lines (100 loc) · 4.59 KB
/
constants.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
125
126
"""
Handle the constants for the entire project and the functions to retrieve/ask them.
"""
import json
import os
import pandas as pd
from colorama import Fore, Style
from get_fc import get_fc
from get_valid_sites import get_valid_sites
from version import __title__
def load_logs():
"""
Get the log file TsOutAudits.xlsx and the database database.json . In case the files are not in the folder FOLDER
where the main file is stored, generate empty pd DataFrame and empty dict.
:return: (pd.DataFrame, dict())
"""
try:
super_log = pd.read_excel(f"{FOLDER}TsOutAuditsLog.xlsx")
except FileNotFoundError:
print("WARNING: TsOutAuditsLog.xlsx not found.")
super_log = pd.DataFrame()
try:
with open(f"{FOLDER}database.json") as json_file:
prices_database = json.load(json_file)
except FileNotFoundError:
print("WARNING: database.json not found.")
prices_database = dict()
return super_log, prices_database
def ask_badge():
while True: # ask for badge
print(COLOR + "Please scan your badge\n->", end="")
login = input()
if len(login) > 0 and login.isdigit():
return login
else:
print(COLOR_RED + "Invalid badge. Please try again.")
def download_fc(fc, folder):
print(COLOR_RED + f"{fc} not recognized. Downloading valid FCs from https://rodeo-dub.amazon.com .")
sites = get_valid_sites(folder)
return sites
def ask_fc(folder):
while True:
default_fc = get_fc(os.getlogin())
print(COLOR + f"Are you auditing Transshipment Out in {default_fc}?(yes/no)\n->", end="")
# colorama doesn't work with input, so need to split input from print
is_default_fc_correct = input().strip().lower()
if is_default_fc_correct == "yes":
fc = default_fc
return fc
elif is_default_fc_correct == "no":
print(COLOR + "Please provide the site in which you are auditing.\n->", end="")
fc = input().strip().upper()
try:
with open(folder + "sites.json") as json_file:
sites = json.load(json_file)
if fc in sites:
return fc
else:
sites = download_fc(fc, folder)
if fc in sites:
return fc
else:
print(COLOR_RED + f"{fc} is not recognized. Are you sure {fc} is correct?(yes/no)\n->", end="")
confirm = input().strip().lower()
if confirm == "yes":
return fc
except FileNotFoundError:
fc = download_fc(fc, folder)
if fc is not None:
return fc
except:
print(COLOR_RED + f"ERROR: impossible to check if {fc} is a valid site. If {fc} is not correct, "
f"please restart {__title__} .")
return fc
else:
print(COLOR_RED + "Invalid answer. Please insert yes or no.")
def ask_amz_domain():
while True:
domains = ('ae', 'cn', 'in', 'ca', 'co.uk', 'com.br', None, 'fr', 'es', 'de', 'it', 'co.jp', 'com.mx', 'sg',
'com')
print(COLOR + "Please provide the domain of the relevant amazon website.\n(E.g.: if the FC is in Italy, "
"amazon.it is the relevant amazon website, so insert: it ; if the FC is in the US, amazon.com is "
"the relevant website, so insert: com ; etc.)\n->", end="")
domain = input().strip().lower()
if domain in domains:
return domain
else:
print(COLOR_RED + f"This domain is not recognized. Are you sure {domain} is correct?(yes/no)\n->",
end="")
confirmation = input().strip().lower()
if confirmation == "yes":
return domain
ESCALATION_MSG = "Please check again. If the error persists, start escalation procedure."
FOLDER = "Audit_Files/" # folder where logs are saved
COLOR = Style.BRIGHT + Fore.MAGENTA # easily change all colours
# COLOR = "" # uncomment to remove colors
COLOR_RED = Style.BRIGHT + Fore.RED
# COLOR_RED = "" # uncomment to remove colors
COLOR_GREEN = Style.BRIGHT + Fore.GREEN
# COLOR_GREEN = "" # uncomment to remove colors