Example #1
0
def de_create(de_name, folderID):
    try:
        debug = False
        stubObj = f.ET_Client(False, debug)
        target_de = str(de_name)
        target_folder = int(folderID)  #502  #API_GEN

        # Create  Data Extension
        print('Creating Data Extension %s' % target_de)
        de = f.ET_DataExtension()
        de.auth_stub = stubObj

        de.props = {
            "Name": target_de,
            "CustomerKey": target_de,
            "CategoryID": target_folder
        }
        # de.columns = get_columns(table_name)
        de.columns = get_columns_with_datatypes(
            table_name)  # switched to new version with data types

        # de.columns = [{'Name': 'sk', 'FieldType': 'Decimal', 'MaxLength': '38'},
        #               {'Name': 'id', 'FieldType': 'Text', 'MaxLength': '1024'}]

        print("DE_COLUMNS = %s" % de.columns)

        properties = de.props
        de.search_filter = {
            'Property': 'CustomerKey',
            'SimpleOperator': 'equals',
            'Value': target_de
        }
        filter = de.search_filter
        de_exists = de.get(properties, filter)

        if len(de_exists.results) == 0:  # If DE does not exist, post
            post_response = de.post()
            print('Post Status: ' + str(post_response.status))
            print('Code: ' + str(post_response.code))
            print('Message: ' + str(post_response.message))
            print('Results: ' + str(post_response.results))
        else:
            # pass
            # TODO: Drop and Recreate DE - [COMPLETED]
            print("Warning: DE exists. Deleting DE %s" % target_de)
            delResponse = de.delete()
            print('Delete Status: ' + str(delResponse.status))
            print('Code: ' + str(delResponse.code))

            print("Creating DE %s" % target_de)
            post_response = de.post()
            print('Post Status: ' + str(post_response.status))
            print('Code: ' + str(post_response.code))

    except Exception as e:
        print('Caught exception: ' + str(e))
        print(e)
 def getName(self):
     if self.Name is None:
         if self.CustomerKey is None:
             raise Exception('Unable to process DataExtension::Row request due to CustomerKey and Name not being defined on ET_DatExtension::row')
         else:
             de = FuelSDK.ET_DataExtension()
             de.auth_stub = self.auth_stub
             de.props = ["Name", "CustomerKey"]
             de.search_filter = {'Property': 'CustomerKey', 'SimpleOperator': 'equals', 'Value': self.CustomerKey}
             getResponse = de.get()
             if getResponse.status and len(getResponse.results) == 1 and 'Name' in getResponse.results[0]:
                 self.Name = getResponse.results[0]['Name']
             else:
                 raise Exception('Unable to process DataExtension::Row request due to unable to find DataExtension based on CustomerKey')
Example #3
0
    def describe_all_de(self, args):
        """
        describe all data extension.

        :param string customer_key: data extension's customer key
        :return: data extension's name array.
        """
        de = FuelSDK.ET_DataExtension()
        de.auth_stub = self.client
        de.props = ["Name", "CustomerKey", "ObjectID"]
        response = de.get()

        writer = csv.writer(sys.stdout,
                            quoting=csv.QUOTE_ALL,
                            lineterminator='\n')
        writer.writerow(de.props)

        for result in response.results:
            writer.writerow([
                result.Name.encode("utf-8"),
                result.CustomerKey.encode("utf-8"),
                result.ObjectID.encode("utf-8")
            ])
Example #4
0
import FuelSDK as f

# try:
debug = False
stubObj = f.ET_Client(False, debug)
DE_NAME = "DE_SAT_001"

# Create  Data Extension
print('>>> Create Data Extension')
de = f.ET_DataExtension()
de.auth_stub = stubObj
# de.props = {"Name", "CustomerKey"}
# de.props = {
#     "Name": "MyDataExtension"
#     , "Description": "My first data extension"
#     , "IsSendable": True
#     , "SendableDataExtensionField": "CustomerID"
#     , "SendableSubscriberField": "_SubscriberKey"
# }
response = de.get()
print(response)