Subversion Repositories SmartDukaan

Rev

Rev 1251 | Rev 4014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
644 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 WarehouseAllocation
14
from shop2020.thriftpy.logistics.ttypes import WarehouseLocation
15
 
16
def load_warehouse_allocations(filename):
1251 chandransh 17
    DataService.initialize('logistics')
644 chandransh 18
    workbook = xlrd.open_workbook(filename)
19
    sheet = workbook.sheet_by_index(0)
20
    num_rows = sheet.nrows
21
    for rownum in range(1, num_rows):
22
        pincode, warehouse_loc = sheet.row_values(rownum)[0:2]
1433 ankur.sing 23
        warehouse_allocation = None
24
        try:
25
            warehouse_allocation = WarehouseAllocation.query.filter_by(pincode = pincode).one()
26
        except:
27
            warehouse_allocation = WarehouseAllocation()
28
            warehouse_allocation.pincode = str(int(pincode))
29
            session.add(warehouse_allocation)
644 chandransh 30
        warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]
31
    session.commit()
32
 
33
def main():
34
    parser = optparse.OptionParser()
35
    parser.add_option("-f", "--file", dest="filename",
36
                   type="string", help="Read the serviceable location list from FILE",
37
                   metavar="FILE")
38
    (options, args) = parser.parse_args()
39
    if len(args) != 0:
40
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
41
    filename = options.filename
42
    if filename is None:
43
        parser.error("A filename must be provided. Use -h for more details.")
44
    load_warehouse_allocations(filename)
45
 
46
if __name__ == '__main__':
47
    main()