Rev 1504 | Rev 4090 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonimport 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 Provider,\DestinationProviderAllocationfrom shop2020.thriftpy.logistics.ttypes import WarehouseLocation,\LogisticsServiceExceptiondef load_providers(filename, sheet_no, db_hostname):DataService.initialize(dbname='logistics', db_hostname=db_hostname)workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(sheet_no)num_rows = sheet.nrowsproviders = Provider.query.all()provider_map = dict([(p.name, p) for p in providers])provider_for_warehouse_location = {}for rownum in range(1, num_rows):dest_pincode, provider_for_warehouse_location[WarehouseLocation.Delhi], provider_for_warehouse_location[WarehouseLocation.Mumbai],\provider_for_warehouse_location[WarehouseLocation.Bangalore], provider_for_warehouse_location[WarehouseLocation.Kolkata] = sheet.row_values(rownum)[0:5]dest_pincode = str(int(dest_pincode))for warehouse_loc, provider_name in provider_for_warehouse_location.iteritems():if provider_name == '' or provider_name == None:continuetry:query = DestinationProviderAllocation.query.filter_by(destination_pin = dest_pincode)query = query.filter_by(warehouse_location = warehouse_loc)dpa = query.one()except:dpa = DestinationProviderAllocation()dpa.destination_pin = dest_pincodedpa.warehouse_location = warehouse_locprovider = provider_map[provider_name]if provider is None:raise LogisticsServiceException(103, "Invalid provider --> " + provider_name)if sheet_no == 0:dpa.provider_less_amount = providerelse:dpa.provider_more_amount = providersession.commit()def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="DestinationProviderAllocation.xls", type="string",help="Read the providers list for different destinations and warehouse locations 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_providers(filename, 0, options.hostname)load_providers(filename, 1, options.hostname)if __name__ == '__main__':main()