Пример #1
0
import ET_Client

try:
    debug = False
    stubObj = ET_Client.ET_Client(False, debug)

    # Retrieve All Folder with GetMoreResults
    print('>>> Retrieve All Folder with GetMoreResults')
    getFolder = ET_Client.ET_Folder()
    getFolder.auth_stub = stubObj
    getFolder.props = [
        "ID", "Client.ID", "ParentFolder.ID", "ParentFolder.CustomerKey",
        "ParentFolder.ObjectID", "ParentFolder.Name",
        "ParentFolder.Description", "ParentFolder.ContentType",
        "ParentFolder.IsActive", "ParentFolder.IsEditable",
        "ParentFolder.AllowChildren", "Name", "Description", "ContentType",
        "IsActive", "IsEditable", "AllowChildren", "CreatedDate",
        "ModifiedDate", "Client.ModifiedBy", "ObjectID", "CustomerKey",
        "Client.EnterpriseID", "Client.CreatedBy"
    ]
    getResponse = getFolder.get()
    print('Retrieve Status: ' + str(getResponse.status))
    print('Code: ' + str(getResponse.code))
    print('Message: ' + str(getResponse.message))
    print('MoreResults: ' + str(getResponse.more_results))
    print('Results Length: ' + str(len(getResponse.results)))
    #print 'Results: ' + str(getResponse.results)

    while getResponse.more_results:
        print('>>> Continue Retrieve All Folder with GetMoreResults')
        getResponse = getFolder.getMoreResults()
Пример #2
0
    def run(self):
        '''
        Main execution code
        '''
        output = []
        output_title = []

        params = self.cfg_params  # noqac

        # Get proper list of tables
        client_id = params.get(CLIENT_ID)
        client_secret = params.get(CLIENT_SECRET)
        subdomain = params.get(SUBDOMAIN)
        sub_id = params.get(MID)
        scope = params.get(SCOPE)

        stubObj = ET_Client.ET_Client(
            False, False, {
                'clientid': client_id,
                'clientsecret': client_secret,
                'wsdl_file_local_loc':
                DEFAULT_FILE_INPUT + '/ExactTargetWSDL.xml',
                'authenticationurl':
                'https://' + subdomain + '.auth.marketingcloudapis.com/',
                'useOAuth2Authentication': 'True',
                'accountId': sub_id
            })

        if scope == ('Subscribers').lower():
            getSub = ET_Client.ET_Subscriber()
            getSub.props = ["SubscriberKey", "EmailAddress", "Status"]
            getSub.auth_stub = stubObj
            getResponse = getSub.get()
            result = getResponse.results
            output = [(x['EmailAddress'], x['SubscriberKey'], x['Status'])
                      for x in result]
            output_title = ['email', 'subscriber_key', 'status']
        elif scope == ('DataExtensions').lower():
            de = ET_Client.ET_DataExtension()
            de.auth_stub = stubObj
            de.props = ["CustomerKey", "Name", "Description"]
            getResponse = de.get()
            result = getResponse.results
            output = [(x['CustomerKey'], x['Name'], x['Description'])
                      for x in result]
            output_title = ['customerkey', 'name', 'description']
        elif scope == ('Folders').lower():
            getFolder = ET_Client.ET_Folder()
            getFolder.auth_stub = stubObj
            getFolder.props = [
                "ID", "Client.ID", "ParentFolder.ID",
                "ParentFolder.CustomerKey", "ParentFolder.ObjectID",
                "ParentFolder.Name", "ParentFolder.Description",
                "ParentFolder.ContentType", "ParentFolder.IsActive",
                "ParentFolder.IsEditable", "ParentFolder.AllowChildren",
                "Name", "Description", "ContentType", "IsActive", "IsEditable",
                "AllowChildren", "CreatedDate", "ModifiedDate",
                "Client.ModifiedBy", "ObjectID", "CustomerKey",
                "Client.EnterpriseID", "Client.CreatedBy"
            ]
            getResponse = getFolder.get()
            result = getResponse.results
            output = [(x['Name'], x['ID'], x['CustomerKey'], x['ObjectID'])
                      for x in result]
            output_title = ['name', 'id', 'customerkey', 'objectid']

        output_file = DEFAULT_TABLE_DESTINATION + scope + '.csv'
        logging.info(output_file)

        with open(output_file, 'w') as out:
            csv_out = csv.writer(out)
            csv_out.writerow(output_title)
            for row in output:
                csv_out.writerow(row)