| 4961 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
This script alerts the Operations team if we are running out
|
|
|
5 |
of Awb Numbers.
|
|
|
6 |
|
|
|
7 |
@author : Chandranshu
|
|
|
8 |
'''
|
|
|
9 |
import optparse
|
|
|
10 |
import sys
|
|
|
11 |
|
|
|
12 |
if __name__ == '__main__' and __package__ is None:
|
|
|
13 |
import os
|
|
|
14 |
sys.path.insert(0, os.getcwd())
|
|
|
15 |
|
|
|
16 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
17 |
from shop2020.utils.EmailAttachmentSender import mail
|
|
|
18 |
|
|
|
19 |
to_addresses = ["cnc.center@shop2020.in", "sandeep.sachdeva@shop2020.in", "suraj.sharma@shop2020.in"]
|
|
|
20 |
from_user = "cnc.center@shop2020.in"
|
|
|
21 |
from_pwd = "5h0p2o2o"
|
|
|
22 |
|
|
|
23 |
def alert(provider_id, type, threshold):
|
|
|
24 |
logistics_client = LogisticsClient().get_client()
|
|
|
25 |
provider = logistics_client.getProvider(provider_id)
|
|
|
26 |
count = logistics_client.getFreeAwbCount(provider_id, type)
|
|
|
27 |
print count
|
|
|
28 |
if count <= threshold:
|
| 5202 |
rajveer |
29 |
text = "Only %d AWB Numbers left for Bluedart. Kindly get it replineshed." % count
|
|
|
30 |
mail(from_user, from_pwd, to_addresses, "AWB alert for " + provider.name + " for " + type, text)
|
| 4961 |
rajveer |
31 |
|
|
|
32 |
def main():
|
|
|
33 |
parser = optparse.OptionParser()
|
|
|
34 |
parser.add_option("-p", "--provider", dest="provider",
|
|
|
35 |
default="1", type="int",
|
|
|
36 |
help="The PROVIDER this alert is for",
|
|
|
37 |
metavar="PROVIDER")
|
|
|
38 |
parser.add_option("-t", "--type", dest="type",
|
|
|
39 |
default="Prepaid", type="string",
|
|
|
40 |
help="TYPE of AWB nos. to track",
|
|
|
41 |
metavar="TYPE")
|
|
|
42 |
parser.add_option("-T", "--threshold", dest="threshold",
|
|
|
43 |
default="200", type="int",
|
|
|
44 |
help="The THRESHOLD below which the alert should be raised",
|
|
|
45 |
metavar="THRESHOLD")
|
|
|
46 |
(options, args) = parser.parse_args()
|
|
|
47 |
if len(args) != 0:
|
|
|
48 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
49 |
alert(options.provider, options.type, options.threshold)
|
|
|
50 |
|
|
|
51 |
if __name__ == '__main__':
|
|
|
52 |
main()
|