Rev 5721 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''It loads data into the ServiceableLocationDetails and DeliveryEstinatetables.@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 Provider,\ServiceableLocationDetails, DeliveryEstimatefrom shop2020.thriftpy.logistics.ttypes import StationType, WarehouseLocationdef load_service_details(filename, provider_name, db_hostname):DataService.initialize(dbname='logistics', db_hostname=db_hostname)#provider_name = provider_name.lower()provider = Provider.get_by(name=provider_name)if provider is None:provider = Provider()provider.name = provider_namesession.commit()workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(0)num_rows = sheet.nrowsdelivery_times = {}for rownum in range(1, num_rows):dest_pincode, dest_code, exp, cod, station_type,\delivery_times[WarehouseLocation.Delhi] = sheet.row_values(rownum)[0:6]#delivery_times[WarehouseLocation.Delhi], delivery_times[WarehouseLocation.Mumbai],\# delivery_times[WarehouseLocation.Bangalore], delivery_times[WarehouseLocation.Kolkata] = sheet.row_values(rownum)[0:10]dest_pincode = str(int(dest_pincode))dest_code = str(dest_code)sld = ServiceableLocationDetails()sld.provider = providersld.dest_pincode = dest_pincodesld.dest_code = dest_codesld.exp = True if exp in [1, 'Yes'] else Falsesld.cod = True if cod in [1, 'Yes'] else Falseif station_type in ["Aramex Own Station", "A"]:sld.station_type = StationType.OWN_STATIONif station_type in ["Associate Station", "B"]:sld.station_type = StationType.ASSOCIATE_STATIONfor warehouse_loc, delivery_time in delivery_times.iteritems():if delivery_time == '' or delivery_time == None:continuedelivery_estimate = DeliveryEstimate()delivery_estimate.destination_pin = str(int(dest_pincode))delivery_estimate.provider = providerdelivery_estimate.warehouse_location = warehouse_locdelivery_estimate.delivery_time = int(delivery_time)session.commit()def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="ServiceableLocations.xls", type="string",help="Read the serviceable location list from FILE",metavar="FILE")parser.add_option("-P", "--provider", dest="provider_name",type="string", help="Create these entries for PROVIDER",metavar="PROVIDER")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.filenameprovider_name = options.provider_nameif filename is None or provider_name is None:parser.error("A provider's name and a filename must be provided. Use -h for more details.")load_service_details(filename, provider_name, options.hostname)if __name__ == '__main__':main()