Rev 4014 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''Loads data into WarehouseAllocation table which is used to determinethe logistics location of the warehouse which will be used to fulfulorders for this pincode.@author: Chandranshu'''import optparseimport xlrdfrom elixir import *if __name__ == '__main__' and __package__ is None:import sysimport ossys.path.insert(0, os.getcwd())from shop2020.logistics.service.impl import DataServicefrom shop2020.logistics.service.impl.DataService import WarehouseAllocationfrom shop2020.thriftpy.logistics.ttypes import WarehouseLocationdef load_warehouse_allocations(filename, db_hostname):DataService.initialize(dbname='logistics', db_hostname=db_hostname)workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowsfor rownum in range(1, num_rows):pincode, warehouse_loc = sheet.row_values(rownum)[0:2]warehouse_allocation = Nonetry:warehouse_allocation = WarehouseAllocation.query.filter_by(pincode = pincode).one()except:warehouse_allocation = WarehouseAllocation()warehouse_allocation.pincode = str(int(pincode))session.add(warehouse_allocation)warehouse_allocation.primary_warehouse_location = WarehouseLocation._NAMES_TO_VALUES[warehouse_loc]session.commit()def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",type="string", help="Read the serviceable location list from FILE",metavar="FILE")parser.add_option("-H", "--host", dest="hostname",default="localhost",type="string", help="The HOST where the DB server is running",metavar="HOST")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")filename = options.filenameif filename is None:parser.error("A filename must be provided. Use -h for more details.")load_warehouse_allocations(filename, options.hostname)if __name__ == '__main__':main()