Skip to content

Instantly share code, notes, and snippets.

@ojmccall
ojmccall / Deploy IS.py
Created January 24, 2023 22:58
deployment script for slack app to deploy IS datasets
import pandas as pd
import requests
from requests.auth import HTTPBasicAuth
from google.cloud import storage
import calendar
import datetime
from datetime import timedelta
import sys
import ast
from os import environ
@ojmccall
ojmccall / Slack DE Builder.py
Last active September 15, 2022 12:22
Slack DE builder.py
def sfmc_api(event,context):
import requests
import json
from google.cloud import storage
from time import gmtime, strftime
import pandas as pd
import xml.etree.ElementTree as ET
import ast
import sys
#I use this to store my token value and API credentials via Secrets Manager
@ojmccall
ojmccall / Slack Message Router.py
Created September 10, 2022 04:39
Slack Message Router
import json
import functions_framework
import requests
from flask import Flask, request, jsonify
from datetime import timedelta
from google.cloud import storage
import datetime
@ojmccall
ojmccall / DHW to SFMC.py
Last active August 25, 2022 23:28
python for CF to run SQL and post to SFMC
import json
import psycopg2
import pandas as pd
import requests
#DB connection
dbname = "DB Name here"
host = "host info here - eg your redshift instance host"
port = "5439"
user = "username here"
@ojmccall
ojmccall / S3 trigger extended.py
Created August 18, 2022 06:23
Lambda to trigger SFMC import from S3
import json
import urllib.parse
import boto3
import requests
client_id = "client id here "
client_secret = "client secret here"
baseURL = "unique url string here"
automationURL = f"https://{baseURL}.rest.marketingcloudapis.com/automation/v1/automations/trigger"
@ojmccall
ojmccall / unzip.py
Created May 17, 2022 08:35
lambda function to unzip file from SFMC
import urllib
import zipfile
import boto3
import io
s3 = boto3.client('s3')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.quote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8'))
@ojmccall
ojmccall / GCP - SFMC SFTP Copy to GCS.py
Created January 12, 2022 23:03
CF - SFMC SFTP TO GCS
def SFMC_SFTP(request):
import pysftp
import tempfile
import os
from shutil import copy
from google.cloud import storage
host = "your SFMC Host here"
username ="SFMC Username here"
password = "Password"
@ojmccall
ojmccall / GCP - SFMC Find & Replace 4.py
Created September 25, 2021 05:56
GCP - SFMC Find & Replace Section 4
for JSON in Actarray:
change = 0
if JSON["content"].find(oldName) >-1:
id = JSON["id"]
customerKey = JSON["customerKey"]
RawContent = JSON["content"]
content = RawContent.replace(oldName,newName)
data = {
@ojmccall
ojmccall / GCP - SFMC Find & Replace 3.py
Created September 25, 2021 05:55
GCP - SFMC Find & Replace Section 3
##Change Content Here
Types = [195,196,197,205,207,208,220]
for idx, val in enumerate(Types):
PageNumber = 1
Actarray = []
count = 1
ContentId = val
while len(Actarray) < count:
@ojmccall
ojmccall / GCP - SFMC Find & Replace 2.py
Created September 25, 2021 05:54
GCP- SFMC Find & Replace Section 2
contentChanged = 0
SQLChanged = 0
SSJSChanged = 0
#get Token Here
try:
url = "https://"+baseURL+".auth.marketingcloudapis.com/v2/Token"
data = {"grant_type":"client_credentials",
"client_id":client_id,