Example: Basic Code to use Python and Split REST API to Extract Split names that serve 100% treatment in default rule and have not been changed for a specific time for a given Workspace/Environment.
This script is useful to detect old Splits that can be removed from the code as the feature is completely enabled or disabled and no changes done to the Split for certain time.
Environment:
- Python 2.7.15
- request 2.20.1
How to use:
- Download class wrapper for Admin API from the following link
SplitAPI.py
- Script code below, update your relevant Split Admin API Key, Workspace and Environment Names and the target date threshold for Splits last modified date. The script will print out the split name, last modified datetime and treatment name that is served 100%.
import SplitAPI
import datetime
############################################
workspaceName="Default"
environmentName="Production"
LastModifiedTime=x = datetime.datetime(2020, 5, 1)
############################################
mySplit = SplitAPI.SplitAPI('ADMIN API KEY')
workspaceId = mySplit.GetWorkspaceId(workspaceName)
splits = mySplit.GetSplitsInEnvironment(workspaceId, environmentName)
epochLastDatetime = float(LastModifiedTime.strftime('%s'))
for split in splits:
highestPercentage = 0;
treatmentAt100 = ""
for treatment in split["defaultRule"]:
if highestPercentage < int(treatment["size"]):
highestPercentage = int(treatment["size"])
treatmentAt100 = treatment["treatment"]
splitModifiedTime = float(split["lastUpdateTime"])/1000
if epochLastDatetime>splitModifiedTime and highestPercentage==100:
print split["name"], datetime.datetime.utcfromtimestamp(splitModifiedTime), treatmentAt100
Comments
0 comments
Please sign in to leave a comment.