| 644 |
chandransh |
1 |
#!/usr/bin/python
|
| 4090 |
chandransh |
2 |
'''
|
|
|
3 |
It loads data into the ServiceableLocationDetails and DeliveryEstinate
|
|
|
4 |
tables.
|
| 644 |
chandransh |
5 |
|
| 4090 |
chandransh |
6 |
@author: Chandranshu
|
|
|
7 |
'''
|
| 644 |
chandransh |
8 |
import optparse
|
|
|
9 |
import xlrd
|
|
|
10 |
from elixir import *
|
|
|
11 |
|
|
|
12 |
if __name__ == '__main__' and __package__ is None:
|
|
|
13 |
import sys
|
|
|
14 |
import os
|
|
|
15 |
sys.path.insert(0, os.getcwd())
|
|
|
16 |
|
|
|
17 |
from shop2020.logistics.service.impl import DataService
|
|
|
18 |
from shop2020.logistics.service.impl.DataService import Provider,\
|
|
|
19 |
ServiceableLocationDetails, DeliveryEstimate
|
|
|
20 |
from shop2020.thriftpy.logistics.ttypes import StationType, WarehouseLocation
|
|
|
21 |
|
| 4014 |
chandransh |
22 |
def load_service_details(filename, provider_name, db_hostname):
|
|
|
23 |
DataService.initialize(dbname='logistics', db_hostname=db_hostname)
|
| 644 |
chandransh |
24 |
|
| 5724 |
rajveer |
25 |
#provider_name = provider_name.lower()
|
| 644 |
chandransh |
26 |
provider = Provider.get_by(name=provider_name)
|
|
|
27 |
if provider is None:
|
|
|
28 |
provider = Provider()
|
|
|
29 |
provider.name = provider_name
|
|
|
30 |
session.commit()
|
|
|
31 |
|
|
|
32 |
workbook = xlrd.open_workbook(filename)
|
|
|
33 |
sheet = workbook.sheet_by_index(0)
|
|
|
34 |
num_rows = sheet.nrows
|
|
|
35 |
delivery_times = {}
|
|
|
36 |
for rownum in range(1, num_rows):
|
| 5721 |
rajveer |
37 |
dest_pincode, dest_code, exp, cod, station_type,\
|
|
|
38 |
delivery_times[WarehouseLocation.Delhi] = sheet.row_values(rownum)[0:6]
|
| 3044 |
chandransh |
39 |
#delivery_times[WarehouseLocation.Delhi], delivery_times[WarehouseLocation.Mumbai],\
|
|
|
40 |
# delivery_times[WarehouseLocation.Bangalore], delivery_times[WarehouseLocation.Kolkata] = sheet.row_values(rownum)[0:10]
|
| 644 |
chandransh |
41 |
dest_pincode = str(int(dest_pincode))
|
|
|
42 |
dest_code = str(dest_code)
|
|
|
43 |
sld = ServiceableLocationDetails()
|
|
|
44 |
sld.provider = provider
|
|
|
45 |
sld.dest_pincode = dest_pincode
|
|
|
46 |
sld.dest_code = dest_code
|
| 1433 |
ankur.sing |
47 |
sld.exp = True if exp in [1, 'Yes'] else False
|
|
|
48 |
sld.cod = True if cod in [1, 'Yes'] else False
|
| 731 |
chandransh |
49 |
if station_type in ["Aramex Own Station", "A"]:
|
| 644 |
chandransh |
50 |
sld.station_type = StationType.OWN_STATION
|
| 731 |
chandransh |
51 |
if station_type in ["Associate Station", "B"]:
|
| 644 |
chandransh |
52 |
sld.station_type = StationType.ASSOCIATE_STATION
|
|
|
53 |
|
|
|
54 |
for warehouse_loc, delivery_time in delivery_times.iteritems():
|
| 731 |
chandransh |
55 |
if delivery_time == '' or delivery_time == None:
|
|
|
56 |
continue
|
| 644 |
chandransh |
57 |
delivery_estimate = DeliveryEstimate()
|
|
|
58 |
delivery_estimate.destination_pin = str(int(dest_pincode))
|
|
|
59 |
delivery_estimate.provider = provider
|
|
|
60 |
delivery_estimate.warehouse_location = warehouse_loc
|
|
|
61 |
delivery_estimate.delivery_time = int(delivery_time)
|
|
|
62 |
session.commit()
|
|
|
63 |
|
|
|
64 |
def main():
|
|
|
65 |
parser = optparse.OptionParser()
|
|
|
66 |
parser.add_option("-f", "--file", dest="filename",
|
|
|
67 |
default="ServiceableLocations.xls", type="string",
|
|
|
68 |
help="Read the serviceable location list from FILE",
|
|
|
69 |
metavar="FILE")
|
|
|
70 |
parser.add_option("-P", "--provider", dest="provider_name",
|
|
|
71 |
type="string", help="Create these entries for PROVIDER",
|
|
|
72 |
metavar="PROVIDER")
|
| 4014 |
chandransh |
73 |
parser.add_option("-H", "--host", dest="hostname",
|
|
|
74 |
default="localhost",
|
|
|
75 |
type="string", help="The HOST where the DB server is running",
|
|
|
76 |
metavar="HOST")
|
| 644 |
chandransh |
77 |
(options, args) = parser.parse_args()
|
|
|
78 |
if len(args) != 0:
|
|
|
79 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
80 |
filename = options.filename
|
|
|
81 |
provider_name = options.provider_name
|
|
|
82 |
if filename is None or provider_name is None:
|
|
|
83 |
parser.error("A provider's name and a filename must be provided. Use -h for more details.")
|
| 4014 |
chandransh |
84 |
load_service_details(filename, provider_name, options.hostname)
|
| 644 |
chandransh |
85 |
|
|
|
86 |
if __name__ == '__main__':
|
|
|
87 |
main()
|