Last active
September 4, 2021 03:25
-
-
Save ojmccall/80375fb6971274b26ccb2c8a87b1f1f6 to your computer and use it in GitHub Desktop.
GCP - SFMC Data Extension Builder 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get csv values to create DE | |
try: | |
df = pd.read_csv(fullpath) | |
df = df.fillna("") | |
df_dict = df.to_dict(orient='records') | |
print("df_array: "+str(df_dict)) | |
print("length: "+str(len(df_dict))) | |
fields = [] | |
for column in df: | |
fieldname = column | |
fieldtype = df.at[0,fieldname] | |
fieldlength = str(df.at[1,fieldname]) | |
isprimarykey = str(df.at[2,fieldname]) | |
isrequired = str(df.at[3,fieldname]) | |
fieldscale = str(df.at[4,fieldname]) | |
defaultvalue = str(df.at[5,fieldname]) | |
SOAPField = "<Field>" | |
SOAPField +="<Name>"+fieldname+"</Name>" | |
SOAPField += "<FieldType>"+fieldtype+"</FieldType>" | |
if fieldtype == "Text" or fieldtype == "Decimal": | |
SOAPField += "<MaxLength>"+fieldlength+"</MaxLength>" | |
if len(isrequired) >0: | |
SOAPField +="<IsRequired>"+isrequired+"</IsRequired>" | |
if len(isprimarykey) >0: | |
SOAPField += "<IsPrimaryKey>"+isprimarykey+"</IsPrimaryKey>" | |
if len(fieldscale) >0: | |
SOAPField += "<Scale>"+fieldscale+"</Scale>" | |
if len(defaultvalue) >0: | |
SOAPField += "<DefaultValue>"+defaultvalue+"</DefaultValue>" | |
#Add additional field config here to meet your requirements | |
SOAPField += "</Field>" | |
fields.append(SOAPField) | |
except Exception as e: print("Dataframe and SOA Content Error:" +e) | |
Fields = ' '.join([str(elem) for elem in fields]) | |
print("string fields: "+Fields) | |
#remove DE config rows from data | |
datarows = df_dict[6:len(df_dict)] | |
#compile XML | |
XMLString = ("""<?xml version="1.0" encoding="UTF-8"?> | |
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" | |
xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" | |
xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> | |
<s:Header> | |
<a:Action s:mustUnderstand="1">Create</a:Action> | |
<a:To s:mustUnderstand="1">"""+SOAPEndpoint+"""</a:To> | |
<fueloauth xmlns="http://exacttarget.com">"""+token+"""</fueloauth> | |
</s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI"> | |
<Options/> | |
<Objects xsi:type="DataExtension"> | |
<Name> """ + DEName +"""</Name> | |
<CustomerKey>""" + DEName + """</CustomerKey>"""+Folder+""" | |
<IsSendable>false</IsSendable> | |
<Fields>""" +Fields + """</Fields> | |
</Objects> | |
</CreateRequest> | |
</s:Body> | |
</s:Envelope>""") | |
XML = bytes(XMLString,'utf-8') | |
print("XML here: "+str(XML)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment