| 759 |
chandransh |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
import optparse
|
|
|
4 |
import xlrd
|
|
|
5 |
from elixir import *
|
|
|
6 |
|
|
|
7 |
if __name__ == '__main__' and __package__ is None:
|
|
|
8 |
import sys
|
|
|
9 |
import os
|
|
|
10 |
sys.path.insert(0, os.getcwd())
|
|
|
11 |
|
|
|
12 |
from shop2020.logistics.service.impl import DataService
|
|
|
13 |
from shop2020.logistics.service.impl.DataService import Awb, Provider
|
|
|
14 |
|
|
|
15 |
def load_awb_numbers(filename, provider_name):
|
| 1251 |
chandransh |
16 |
DataService.initialize('logistics')
|
| 759 |
chandransh |
17 |
|
|
|
18 |
provider = Provider.get_by(name=provider_name)
|
|
|
19 |
if provider is None:
|
|
|
20 |
provider = Provider()
|
|
|
21 |
provider.name = provider_name
|
|
|
22 |
session.commit()
|
|
|
23 |
|
|
|
24 |
workbook = xlrd.open_workbook(filename)
|
|
|
25 |
sheet = workbook.sheet_by_index(0)
|
|
|
26 |
num_rows = sheet.nrows
|
|
|
27 |
for rownum in range(1, num_rows):
|
| 873 |
rajveer |
28 |
awb_number = sheet.row_values(rownum)[0]
|
| 759 |
chandransh |
29 |
awb = Awb()
|
| 873 |
rajveer |
30 |
awb.awb_number = int(awb_number)
|
| 759 |
chandransh |
31 |
awb.is_available = True
|
|
|
32 |
awb.provider = provider
|
|
|
33 |
awb.type = "Prepaid"
|
|
|
34 |
session.commit()
|
|
|
35 |
|
|
|
36 |
def main():
|
|
|
37 |
parser = optparse.OptionParser()
|
|
|
38 |
parser.add_option("-f", "--file", dest="filename",
|
|
|
39 |
default="AwbNumbers.xls", type="string",
|
|
|
40 |
help="Read the AWB numbers from FILE",
|
|
|
41 |
metavar="FILE")
|
|
|
42 |
parser.add_option("-P", "--provider", dest="provider_name",
|
|
|
43 |
type="string", help="Load these entries for PROVIDER",
|
|
|
44 |
metavar="PROVIDER")
|
|
|
45 |
(options, args) = parser.parse_args()
|
|
|
46 |
if len(args) != 0:
|
|
|
47 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
48 |
filename = options.filename
|
|
|
49 |
provider_name = options.provider_name
|
|
|
50 |
if filename is None or provider_name is None:
|
|
|
51 |
parser.error("A provider's name and a filename must be provided. Use -h for usage details.")
|
|
|
52 |
load_awb_numbers(filename, provider_name)
|
|
|
53 |
|
|
|
54 |
if __name__ == '__main__':
|
|
|
55 |
main()
|