Rev 4014 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''Loads the holidays in the PublicHolidays table.It expects a sheet to have two columns: date and occassion.@author: Ankur Singhal'''import optparseimport xlrdfrom elixir import *import timeif __name__ == '__main__' and __package__ is None:import sysimport ossys.path.insert(0, os.getcwd())from shop2020.logistics.service.impl import DataServicefrom shop2020.logistics.service.impl.DataService import PublicHolidaysdef load_holidays(filename, sheet_no, db_hostname):DataService.initialize(dbname='logistics', db_hostname=db_hostname)workbook = xlrd.open_workbook(filename)sheet = workbook.sheet_by_index(sheet_no)num_rows = sheet.nrowsfor rownum in range(1, num_rows):holiday_date, occasion = sheet.row_values(rownum)[0:2]print str(holiday_date)holiday_date = time.strptime(str(holiday_date), '%d/%m/%y')holiday_date = time.strftime('%Y-%m-%d', holiday_date)print holiday_datetry:holiday = PublicHolidays.query.filter_by(date = holiday_date).one()except:holiday = PublicHolidays()holiday.date = holiday_dateholiday.occasion = occasionsession.commit()def main():parser = optparse.OptionParser()parser.add_option("-f", "--file", dest="filename",default="Holidays.xls", type="string",help="Read the holiday list",metavar="FILE")parser.add_option("-H", "--host", dest="hostname",default="localhost",type="string", help="The HOST where the DB server is running",metavar="HOST")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")filename = options.filenameif filename is None:parser.error("A filename must be provided. Use -h for more details.")load_holidays(filename, 0, options.hostname)if __name__ == '__main__':main()