Created
June 10, 2011 04:00
-
-
Save tnydwrds/1018204 to your computer and use it in GitHub Desktop.
Bulk deactivation of OpenX 2.8 Source campaigns
This file contains hidden or 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
#!/usr/bin/env python | |
import csv | |
import datetime | |
import xmlrpclib | |
csv_file_path = "campaigns_to_deactivate.csv" | |
username = "" | |
password = "" | |
domain = "" | |
protocol = "http://" | |
api_path = "/openx/www/api/v2/xmlrpc/" | |
api_url = protocol + domain + api_path | |
# Expire (or complete) campaign immediately by setting end date to yesterday. | |
# The 2.x API will override your time to equivelant of 23:59:59 in your time | |
# zone, so setting end date to previous day is necessary. | |
end_date = datetime.datetime.now() - datetime.timedelta(1) | |
# Read CSV file in universal newline mode to prevent issues when working with | |
# CSV files exported from Excel on OS X. | |
csv_reader = csv.reader(open(csv_file_path, 'rU'), dialect='excel') | |
# Skip first row for headers. | |
csv_reader.next() | |
ox = xmlrpclib.ServerProxy(api_url).ox | |
session_id = ox.logon(username, password) | |
for row in csv_reader: | |
camp_name, camp_id = row[0], int(row[1]) | |
log_message = "Updating => Campaign Name: %s \n" | |
log_message += " Campaign ID: %s" | |
print(log_message % (camp_name, camp_id)) | |
campaign = ox.getCampaign(session_id, camp_id) | |
try: | |
# Skip any campaigns in our list that may have already had an | |
# endDate set. Maybe there are duplicates in the list we have? | |
if campaign['endDate'] < end_date: | |
continue | |
except KeyError: | |
# There was no endDate set. | |
pass | |
campaign['endDate'] = end_date | |
success = ox.modifyCampaign(session_id, campaign) | |
log_message = " Update Success: %s\n" | |
print(log_message % success) | |
ox.logoff(session_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment