Subversion Repositories SmartDukaan

Rev

Rev 1433 | Rev 4014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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