예제 #1
0
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import smartwaiver

# The API Key for your account
api_key = '[INSERT API KEY]'

# Set up your Smartwaiver connection using your API Key
sw = smartwaiver.Smartwaiver(api_key)

# Get a list of all templates
templates = sw.get_waiver_templates()

print('List all waiver templates:\n')
for template in templates:
    print(template.template_id + ': ' + template.title)

# View all accessible properties of a waiver template object in:
# examples/templates/template_properties.php
예제 #2
0
    def Run(self):
        # self.GetWaiverlessMembers()

        # assert 1==2, "math fail!"

        script_start_time = datetime.now()

        time_format_string = '%B %d, %Y at %I:%M%p'

        sw = smartwaiver.Smartwaiver(self.config.get('smartwaiver', 'api_key'))

        # templates = sw.get_waiver_templates()

        # for template in templates:
        # 	print(template.template_id + ': ' + template.title)

        # Get a list of recent signed waivers for this account
        summaries = sw.get_waiver_summaries(100)

        for summary in summaries:
            print("====================================")
            print(summary.waiver_id + ': ' + summary.title)

            WA_ID = None
            print(summary.first_name, summary.last_name)

            for tag in summary.tags:
                if tag.split(' ')[0] == 'WA_ID':
                    WA_ID = int(tag.split(' ')[1])

            sw_fails = 0
            while (1):
                try:
                    waiver = sw.get_waiver(summary.waiver_id, True)
                    break
                except (smartwaiver.exceptions.SmartwaiverHTTPException,
                        smartwaiver.exceptions.SmartwaiverSDKException):
                    print("Smartwaiver Error")
                    sw_fails += 1
                    if sw_fails > 3:
                        raise
                    else:
                        time.sleep(5)
                        continue

            contact = None

            if not WA_ID and summary.is_minor:
                print("Skipping untagged minor waiver")
                continue

            else:
                while (1):
                    try:
                        #Pull contact's info from WA if it exists
                        if WA_ID:
                            contact = self.WA_API.GetContactById(WA_ID)
                        else:
                            contact = self.WA_API.GetContactByEmail(
                                waiver.email)[0]
                            WA_ID = contact['Id']
                        break
                        #print(contact)

                    #If query returns no contact
                    except IndexError:
                        print("Contact does not exist")
                        break
                    except TypeError:
                        print("Failed to connect to WA")
                        time.sleep(60)
                        continue

            if not contact:
                continue
            #If waiver date is not newer than what is currently on the WA profile, don't update
            saved_waiver_date = [
                field['Value'] for field in contact['FieldValues']
                if field['FieldName'] == "WaiverDate"
            ][0]
            print(contact['Email'])
            print("saved waiver date:", saved_waiver_date)
            print("summary created_on date:", summary.created_on)
            if saved_waiver_date and saved_waiver_date.strip() != '':
                print("Has waiver date")
                if datetime.strptime(saved_waiver_date,
                                     "%Y-%m-%d %H:%M:%S") >= datetime.strptime(
                                         summary.created_on,
                                         "%Y-%m-%d %H:%M:%S"):
                    continue

            #update WA account waiver date with the current waiver's date
            print('.' + summary.dob + '.')
            waiver_DOB = datetime.strptime(summary.dob, "%Y-%m-%d")
            WA_DOB = waiver_DOB.strftime("%d %b %Y")
            #print(WA_DOB)
            #print(WA_ID, ":", waiver_date)
            #print(waiver_DOB)
            #print(type(WA_ID))
            #print(type(waiver_date))
            self.SetWaiverDate(WA_ID, summary.created_on)
            time.sleep(3)
            self.SetDOB(WA_ID, summary.dob)