Create a gist now

Instantly share code, notes, and snippets.

Embed
import webbrowser as wb
import time
import os
# replace url_base with your Backstop instance URL
url_base = 'https://[BACKSTOP_URL]'
url_delete_contacts = '/backstop/crm/ManageContacts.do?ACTION=DELETE&id='
# number of seconds to pause before launching another broswer tab
# too low a number might cause "Too Many Connections" errors
sleep_time = 2
# Backstop Party IDs, used in first method
ids = ['001','002','003']
# open in Chrome; Windows currently requires the path explicitly defined
if os.name == 'nt':
browser = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
else:
browser = 'chrome'
# First method: simply grabbing IDs from a list
for id in ids:
wb.get(browser).open(url_base + url_delete_contacts + str(id))
time.sleep(sleep_time)
# Second method: grabbing IDs from a CSV file
with open('backstop_ids.csv') as csvfile:
ids = csv.reader(csvfile)
for id in ids:
wb.get('chrome').open(url_delete_contacts+str(id[0]))
time.sleep(sleep_time)
# BONUS: delete ALL relationships for a given Contact
# be signle and mingle
# uncomment this block below to try at your own risk!
#url_delete_relationships_all = '/backstop/relationships/ManageRelationships.do?ACTION=REMOVE_ALL&sourceId=PartyBean_'
#with open('backstop_ids.csv') as csvfile:
# ids = csv.reader(csvfile)
# for id in ids:
# wb.get('chrome').open(url_delete_contacts+str(id[0]))
# time.sleep(sleep_time)
# TODO
# add error handling
# refactor code to use methods
100001 Alpha
100002 Beta
100003 Charlie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment