-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkDelivered.py
More file actions
101 lines (83 loc) · 3.46 KB
/
markDelivered.py
File metadata and controls
101 lines (83 loc) · 3.46 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
import sys
from concurrent.futures import ThreadPoolExecutor
from utils import files, packages, utils
STANDARD_TIMEOUT = 5 # seconds
SUCCESSES = []
ERRORS = []
def main(file_name: str | None, key_type: str):
"""
The main function that reads data from a file, retrieves package details based on the specified key type, and performs operations on the packages, such as marking them as delivered.
Parameters:
- file_name (str): The name of the file to read data from. Every line should be a package reference (ori, pi, bc)
- key_type (str): The type of key to use for retrieving package details such as bc, ori, pi and so on.
Returns:
None
"""
lines = files.get_data_from_file(file_name)
env = utils.select_env()
orgId = utils.select_org(env)
print(
"Key Types: {}\n".format(key_type.upper())
+ "Keys: \n"
+ "\n".join(map(str, lines))
+ "\n"
)
pkgs = []
for line in lines:
# getting packages from barcode present in file line
pkgs = packages.get_package_details(env, orgId, key_type, line)
if len(pkgs) == 0:
print("> NO PACKAGES FOUND <\n")
print(f"\n{'':=<50}")
print(f"Found {len(pkgs)} packages, Applying filters")
with ThreadPoolExecutor() as pool:
for package in pkgs:
orgId = package["orgId"]
provider = str(package["providerDetails"]["providerName"]).upper()
status = package["packageStatuses"]["status"]
package_id = package["packageId"]
hub_name = package["packageDetails"]["sourceLocation"]["name"]
print(
f"\n---> PACKAGE ID: {package_id}" + " (DELIVERED)"
if status == "DELIVERED"
else "OK"
)
print(f"--> PROVIDER: {provider}")
print(f"--> STATUS: {status}\n")
print(f"--> HUB: {hub_name}")
pool.submit(packages.mark_package_as_delivered, env, orgId, package_id)
# get command line argument
if len(sys.argv) < 3:
print(
"Please, check the correct script usage bellow:\n\n"
+ "PRE REQUISITES:\n"
+ "> A file <file>.txt should be created in this same directory. You should paste the barcodes/ORIs/PIs/etc there\n"
+ "SCRIPT USAGE:\n"
+ "--> python markDelivered.py <file_name> <key_type>\n\n"
+ "-> Accepted key_types:\n"
+ "> pi (Package Id)\n"
+ "> tn (Tracking Number)\n"
+ "> ci (Container Id)\n"
+ "> bc (Shipment Barcode)\n"
+ "> oi (Order Id)\n"
+ "> ori (Order Reference Id)\n"
+ "> ji (Job Id)\n\n"
"SCRIPT EXAMPLE:\n"
+ "--> python replanPackages.py 8506 bc\n"
+ "> This will load all the barcodes on 8506.txt and mark delivered packages that are not already delivered\n\n"
+ "NOTES:\n"
+ "> Check comments on code to update relevant data such as key_type (bc, ori, etc), ORG Environment accordingly to your needs\n"
)
sys.exit(1)
# The file name must be to the requester's hub name (e.g. 8506)
file_name = sys.argv[1].replace(".txt", "").replace(".\\", "")
# A key_type arg must be provided. provide one of the following key_types:
# -> pi (Package Id)
# -> tn (Tracking Number)
# -> ci (Container Id)
# -> bc (Shipment Barcode)
# -> oi (Order Id)
# -> ori (Order Reference Id)
# -> ji (Job Id)
key_type = sys.argv[2].lower()
main(file_name, key_type)