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