Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
759 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 Awb, Provider
14
 
4013 chandransh 15
def load_awb_numbers(filename, provider_id, type, db_hostname):
16
    DataService.initialize(dbname='logistics', db_hostname=db_hostname)
759 chandransh 17
 
3044 chandransh 18
    provider = Provider.get_by(id=provider_id)
759 chandransh 19
    if provider is None:
3044 chandransh 20
        exit()
759 chandransh 21
 
22
    workbook = xlrd.open_workbook(filename)
23
    sheet = workbook.sheet_by_index(0)
24
    num_rows = sheet.nrows
25
    for rownum in range(1, num_rows):
873 rajveer 26
        awb_number = sheet.row_values(rownum)[0]
759 chandransh 27
        awb = Awb()
873 rajveer 28
        awb.awb_number = int(awb_number)
759 chandransh 29
        awb.is_available = True
30
        awb.provider = provider
3044 chandransh 31
        awb.type = type
759 chandransh 32
    session.commit()
33
 
34
def main():
35
    parser = optparse.OptionParser()
36
    parser.add_option("-f", "--file", dest="filename",
37
                   default="AwbNumbers.xls", type="string",
38
                   help="Read the AWB numbers from FILE",
39
                   metavar="FILE")
3044 chandransh 40
    parser.add_option("-P", "--provider", dest="provider_id",
41
                      type="int", help="Load these entries for PROVIDER",
759 chandransh 42
                      metavar="PROVIDER")
3044 chandransh 43
    parser.add_option("-t", "--type", dest="type",
44
                      type="string", help="The TYPE of orders these AWB numbers are for",
45
                      metavar="TYPE")
4013 chandransh 46
    parser.add_option("-H", "--host", dest="hostname",
47
                      default="localhost",
48
                      type="string", help="The HOST where the DB server is running",
49
                      metavar="HOST")
759 chandransh 50
    (options, args) = parser.parse_args()
51
    if len(args) != 0:
52
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
53
    filename = options.filename
3044 chandransh 54
    provider_id = options.provider_id
55
    type = options.type
56
    if filename is None or provider_id is None or type is None:
759 chandransh 57
        parser.error("A provider's name and a filename must be provided. Use -h for usage details.")
4013 chandransh 58
    load_awb_numbers(filename, provider_id, type, options.hostname)
759 chandransh 59
 
60
if __name__ == '__main__':
61
    main()