-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPackageRoute.py
More file actions
107 lines (83 loc) · 3.15 KB
/
getPackageRoute.py
File metadata and controls
107 lines (83 loc) · 3.15 KB
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
import os
import sys
from utils import files, packages, utils
def get_file_name():
"""
Create a unique log file name based on the current script name and timestamp.
Returns:
str: The unique log file name in the format "<script_name><timestamp>.txt".
"""
# Get the name of the current script file
script_file = os.path.basename(sys.argv[0])
# Remove the file extension from the script name
script_name = os.path.splitext(script_file)[0]
# Create the log file name
file_name = script_name + f"{utils.get_formated_now()}.txt"
return file_name
def main(FILENAME, KEY_TYPE):
"""
The main function for retrieving package details.
Parameters:
FILENAME (str): The name of the file containing the key values.
KEY_TYPE (str): The type of key used for package retrieval. Valid options include:
- "pi" (Package Id)
- "bc" (Shipment Barcode)
- "ori" (Order Reference Id)
Returns:
None
"""
env = utils.select_env()
orgId = utils.select_org(env)
lines = files.get_data_from_file(FILENAME)
print("Script is generating your file with the full response... ")
logFile = files.create_logs_file()
files.start_logging(logFile)
for line in lines:
pkgs = packages.get_package_details(env, orgId, KEY_TYPE, line)
for package in pkgs:
packageID = package["packageId"]
hubName = package["packageDetails"]["sourceLocation"]["name"]
try:
routeId = package["planningDetails"]["plannerRouteId"]
except Exception:
print(
"This package/route was probably not executed (not ROUTE_ID found)"
)
routeId = package["planningDetails"]["originalRouteId"]
routeName = package["planningDetails"]["plannerRouteName"]
print(f"Package ID: {packageID}")
print(f"HUB Name: {hubName}")
print(f"Route Name: {routeName}")
print(f"Route ID: {routeId}")
files.stop_logging()
files.close_logs_file(logFile)
print(f"Script finished. Check for {get_file_name()}")
valid_key_types = [
"pi (Package Id)",
"tn (Tracking Number)",
"ci (Container Id)",
"bc (Shipment Barcode)",
"oi (Order Id)",
"ori (Order Reference Id)",
"ji (Job Id)",
]
# get command line argument
if len(sys.argv) < 3:
print(
"\nNO ARGS PROVIDED!\n"
+ "Please, check the correct script usage bellow:\n\n"
+ "SCRIPT USAGE:\n"
+ "--> python getPackageRoute.py <FILE> <KEY_TYPE>\n\n"
+ "-> Accepted KEY_TYPEs:\n"
+ "\n".join(map(str, valid_key_types))
+ "\n\nSCRIPT EXAMPLE:\n"
+ "--> python getPackageRoute.py 'barcodes' bc\n"
+ "> This will load all the barcodes on barcodes.txt and print out their routeIds\n\n"
+ "NOTES:\n"
+ "> Check comments on code to update relevant data such as KEY_TYPE (bc, ori, etc)\n"
)
sys.exit(1)
# The file name must be to the requester's hub name (e.g. 8506)
FILENAME = sys.argv[1].replace(".txt", "").replace(".\\", "")
KEY_TYPE = sys.argv[2].lower()
main(FILENAME, KEY_TYPE)