Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
1730 ankur.sing 1
#!/usr/bin/python
2
 
3
import optparse
4
import xlrd
5
from elixir import *
6
import time
7
 
8
if __name__ == '__main__' and __package__ is None:
9
    import sys
10
    import os
11
    sys.path.insert(0, os.getcwd())
12
 
1737 rajveer 13
from shop2020.logistics.service.impl import DataService
14
from shop2020.logistics.service.impl.DataService import PublicHolidays
15
 
4014 chandransh 16
def load_holidays(filename, sheet_no, db_hostname):
17
    DataService.initialize(dbname='logistics', db_hostname=db_hostname)
1730 ankur.sing 18
 
19
    workbook = xlrd.open_workbook(filename)
20
    sheet = workbook.sheet_by_index(sheet_no)
21
    num_rows = sheet.nrows
22
 
23
    for rownum in range(1, num_rows):
24
        holiday_date, occasion = sheet.row_values(rownum)[0:2]
25
        print str(holiday_date)
26
        holiday_date = time.strptime(str(holiday_date), '%d/%m/%y')
27
        holiday_date = time.strftime('%Y-%m-%d', holiday_date)
28
        print holiday_date
29
 
30
        try:
31
            holiday = PublicHolidays.query.filter_by(date = holiday_date).one()
32
        except:
33
            holiday = PublicHolidays()
34
            holiday.date = holiday_date
35
        holiday.occasion = occasion
36
    session.commit()
37
 
38
def main():
39
    parser = optparse.OptionParser()
40
    parser.add_option("-f", "--file", dest="filename",
41
                   default="Holidays.xls", type="string",
42
                   help="Read the holiday list",
43
                   metavar="FILE")
4014 chandransh 44
    parser.add_option("-H", "--host", dest="hostname",
45
                      default="localhost",
46
                      type="string", help="The HOST where the DB server is running",
47
                      metavar="HOST")
1730 ankur.sing 48
    (options, args) = parser.parse_args()
49
    if len(args) != 0:
50
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
51
    filename = options.filename
52
    if filename is None:
53
        parser.error("A filename must be provided. Use -h for more details.")
4014 chandransh 54
    load_holidays(filename, 0, options.hostname)
1730 ankur.sing 55
 
56
if __name__ == '__main__':
1737 rajveer 57
    main()