Beispiel #1
0
    def action(self):
        config_obj = ApplicationConfig.get_current_config()
        client = SpreadsheetConnector(config_obj.google_user_email, config_obj.google_user_password)
        worksheet = client.get_worksheet(config_obj.holidays_spreadsheet, 6)
        data = worksheet.GetRecords(1, 99999)  # Magic Constant
        dates_new = set([ datetime.datetime.strptime(d.content['data'], '%Y-%m-%d').date() for d in data ])
        dates_old = set(Holiday.all(cache=False))
        dates_diff = dates_new.difference(dates_old)

        if dates_diff:
            holidays = [ Holiday(date=date) for date in dates_diff ]
            DBSession.add_all(holidays)

        INFO(u'%s Holidays added: %s' % (len(dates_diff), dates_diff))
        return Response('ok')