Script 1785: Webinar Creative AutoPause
Purpose:
The Python script automates the pausing and reactivation of webinar creatives based on their cost, ensuring efficient budget management.
To Elaborate
The script is designed to manage the status of webinar creatives by automatically pausing those that exceed a specified cost threshold and reactivating them at the start of a new month. This process helps in maintaining a structured budget allocation (SBA) by ensuring that creatives that are too costly are paused, thereby preventing overspending. The script checks each creative’s cost against a predefined threshold and updates its status to “Paused” if the cost is higher. Additionally, it records the date when the creative was paused. At the beginning of each month, the script reactivates any paused creatives, resetting their status to “Active” and clearing the pause date. This cyclical process ensures that budget allocations are managed efficiently over time.
Walking Through the Code
- Configuration Setting
- The script begins by setting a user-defined cost threshold (
PAUSE_COST_THRESHOLD
) which determines when a creative should be paused.
- The script begins by setting a user-defined cost threshold (
- Date Initialization
- It calculates the current date and identifies the first day of the current month to manage the reactivation of paused creatives.
- Data Preparation
- A sample DataFrame (
inputDf
) is created to simulate the input data, containing columns for publication ID, cost, status, and pause date.
- A sample DataFrame (
- Pausing Logic
- The script checks if the cost of each creative exceeds the
PAUSE_COST_THRESHOLD
. If it does, the status is set to “Paused” and the current date is recorded in the pause date column.
- The script checks if the cost of each creative exceeds the
- Reactivation Logic
- On the first day of the month, the script reactivates any creatives that were previously paused by setting their status back to “Active” and clearing the pause date.
- Output
- Finally, the script prints the updated DataFrame to show the changes in the status and pause dates of the creatives.
Vitals
- Script ID : 1785
- Client ID / Customer ID: 1306922277 / 60268979
- Action Type: Bulk Upload (Preview)
- Item Changed: Ad
- Output Columns: Account, Campaign, Group, Creative ID, Status, Webinar Creative Auto Pause Date
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: ascott@marinsoftware.com (ascott@marinsoftware.com)
- Created by ascott@marinsoftware.com on 2025-03-07 20:04
- Last Updated by ascott@marinsoftware.com on 2025-03-07 20:18
> See it in Action
Python Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
##
## name: Webinar Creative AutoPause
## description:
##
##
## author: ascott@marinsoftware.com
## created: 2025-03-07
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_PUB_ID = 'Pub. ID'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_STATUS = 'Status'
RPT_COL_CREATIVE_TYPE = 'Creative Type'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_CTR = 'CTR %'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_HEADLINE = 'Headline'
RPT_COL_HEADLINE_2 = 'Headline 2'
RPT_COL_HEADLINE_3 = 'Headline 3'
RPT_COL_HEADLINE_4 = 'Headline 4'
RPT_COL_HEADLINE_5 = 'Headline 5'
RPT_COL_HEADLINE_6 = 'Headline 6'
RPT_COL_HEADLINE_7 = 'Headline 7'
RPT_COL_HEADLINE_8 = 'Headline 8'
RPT_COL_HEADLINE_9 = 'Headline 9'
RPT_COL_HEADLINE_10 = 'Headline 10'
RPT_COL_HEADLINE_11 = 'Headline 11'
RPT_COL_HEADLINE_12 = 'Headline 12'
RPT_COL_HEADLINE_13 = 'Headline 13'
RPT_COL_HEADLINE_14 = 'Headline 14'
RPT_COL_HEADLINE_15 = 'Headline 15'
RPT_COL_HEADLINE_PINNED_TO_POSITION_1 = 'Headline Pinned to Position 1'
RPT_COL_HEADLINE_PINNED_TO_POSITION_2 = 'Headline Pinned to Position 2'
RPT_COL_HEADLINE_PINNED_TO_POSITION_3 = 'Headline Pinned to Position 3'
RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE = 'Webinar Creative Auto Pause Date'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_CREATIVE_ID = 'Creative ID'
BULK_COL_STATUS = 'Status'
BULK_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE = 'Webinar Creative Auto Pause Date'
outputDf[BULK_COL_STATUS] = "<<YOUR VALUE>>"
outputDf[BULK_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE] = "<<YOUR VALUE>>"
# user code start here
print(tableize(inputDf.head()))
import pandas as pd
import datetime
# Configuration setting
PAUSE_COST_THRESHOLD = 100 # Set your desired threshold here
# Current date and first day of the month
today = datetime.datetime.now().date()
first_day_of_month = datetime.date(today.year, today.month, 1)
# Sample DataFrame (replace with your actual data)
data = {
"Pub. ID": [1, 2, 3],
"Pub. Cost $": [150, 50, 200],
"Status": ["Active", "Active", "Active"],
"Webinar Creative Auto Pause Date": ["", "", ""]
}
inputDf = pd.DataFrame(data)
# Columns
RPT_COL_PUB_ID = 'Pub. ID'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_STATUS = 'Status'
RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE = 'Webinar Creative Auto Pause Date'
# Setting status to "Paused" and recording the date
inputDf.loc[inputDf[RPT_COL_PUB_COST] > PAUSE_COST_THRESHOLD, RPT_COL_STATUS] = "Paused"
inputDf.loc[inputDf[RPT_COL_PUB_COST] > PAUSE_COST_THRESHOLD, RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE] = today
# Changing status to "Active" on the first day of the month
inputDf.loc[(inputDf[RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE] != "") & (today == first_day_of_month), RPT_COL_STATUS] = "Active"
inputDf.loc[(inputDf[RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE] != "") & (today == first_day_of_month), RPT_COL_WEBINAR_CREATIVE_AUTO_PAUSE_DATE] = ""
# Output the result
print(inputDf)
Post generated on 2025-03-11 01:25:51 GMT