Rev 731 | 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,\ServiceableLocationDetails, DeliveryEstimatefrom shop2020.thriftpy.logistics.ttypes import StationType, WarehouseLocationdef load_service_details(filename, provider_name):DataService.initialize()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, state, exp, cod, station_type,\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 == 1 else Falsesld.cod = True if cod == 1 else Falseif station_type == "Aramex Own Station":sld.station_type = StationType.OWN_STATIONif station_type == "Associate Station":sld.station_type = StationType.ASSOCIATE_STATIONfor warehouse_loc, delivery_time in delivery_times.iteritems():delivery_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")(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)if __name__ == '__main__':main()