| 644 |
chandransh |
1 |
#!/usr/bin/python
|
| 4090 |
chandransh |
2 |
'''
|
|
|
3 |
Loads data into WarehouseAllocation table which is used to determine
|
|
|
4 |
the logistics location of the warehouse which will be used to fulful
|
|
|
5 |
orders for this pincode.
|
| 644 |
chandransh |
6 |
|
| 4090 |
chandransh |
7 |
@author: Chandranshu
|
|
|
8 |
'''
|
| 644 |
chandransh |
9 |
import optparse
|
|
|
10 |
import xlrd
|
|
|
11 |
from elixir import *
|
|
|
12 |
|
|
|
13 |
if __name__ == '__main__' and __package__ is None:
|
|
|
14 |
import sys
|
|
|
15 |
import os
|
|
|
16 |
sys.path.insert(0, os.getcwd())
|
|
|
17 |
|
|
|
18 |
from shop2020.logistics.service.impl import DataService
|
|
|
19 |
from shop2020.logistics.service.impl.DataService import WarehouseAllocation
|
|
|
20 |
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
|
|
|
21 |
|
| 4014 |
chandransh |
22 |
def load_warehouse_allocations(filename, db_hostname):
|
|
|
23 |
DataService.initialize(dbname='logistics', db_hostname=db_hostname)
|
| 644 |
chandransh |
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):
|
|
|
28 |
pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
|
| 1433 |
ankur.sing |
29 |
warehouse_allocation = None
|
|
|
30 |
try:
|
|
|
31 |
warehouse_allocation = WarehouseAllocation.query.filter_by(pincode = pincode).one()
|
|
|
32 |
except:
|
|
|
33 |
warehouse_allocation = WarehouseAllocation()
|
|
|
34 |
warehouse_allocation.pincode = str(int(pincode))
|
|
|
35 |
session.add(warehouse_allocation)
|
| 644 |
chandransh |
36 |
warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]
|
|
|
37 |
session.commit()
|
|
|
38 |
|
|
|
39 |
def main():
|
|
|
40 |
parser = optparse.OptionParser()
|
|
|
41 |
parser.add_option("-f", "--file", dest="filename",
|
|
|
42 |
type="string", help="Read the serviceable location list from FILE",
|
|
|
43 |
metavar="FILE")
|
| 4014 |
chandransh |
44 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
45 |
default="localhost",
|
|
|
46 |
type="string", help="The HOST where the DB server is running",
|
|
|
47 |
metavar="HOST")
|
| 644 |
chandransh |
48 |
(options, args) = parser.parse_args()
|
|
|
49 |
if len(args) != 0:
|
|
|
50 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
51 |
filename = options.filename
|
|
|
52 |
if filename is None:
|
|
|
53 |
parser.error("A filename must be provided. Use -h for more details.")
|
| 4014 |
chandransh |
54 |
load_warehouse_allocations(filename, options.hostname)
|
| 644 |
chandransh |
55 |
|
|
|
56 |
if __name__ == '__main__':
|
|
|
57 |
main()
|