<commit_before>import requests
import xml.etree.ElementTree as ET
import time

API_KEY='myAPIkeyfglIdHkIuRerDBPhgt'
PROJECT_NAME = 'Myproject'
RUNDECKSERVER = 'https://yourrundeckserver.com'

MILISECONDS_IN_THREE_MONTHS = 7889000000
TODAY = int(round(time.time() * 1000))

# API call to get the list of the jobs that exist for a project.
def listJobsForProject(project_mame):
    url = 'https://'+ RUNDECKSERVER +':4443/api/1/jobs'
    payload = { 'project':  project_mame }
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.get(url, params=payload, headers=headers, verify=False)
    return r.text

# Returns list of all the jobids
def getJobIDs(jobsinfo_xml):
    job_ids = []
    root = ET.fromstring(jobsinfo_xml)	
    for jobs in root:
        for job in jobs:
            job_ids.append(job.attrib['id'])
    return job_ids

# API call to get the list of the executions for a Job.      
def getExecutionsForAJob(job_id):
    url = 'https://'+ RUNDECKSERVER +':4443/api/1/job/'+job_id+'/executions'
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.get(url, headers=headers, verify=False)
    return r.text

# Returns a dict {'execution_id01': 'execution_date01', 'execution_id02': 'execution_date02', ... }
def getExecutionDate(executionsinfo_xml):
    execid_dates = {}
    root = ET.fromstring(executionsinfo_xml)
    for executions in root:     
        for execution in executions.findall('execution'):
            execution_id = execution.get('id')
            for date in execution.findall('date-ended'):
                execution_date = date.get('unixtime')
    	    execid_dates[execution_id] = execution_date
    return execid_dates
       
#API call to delete an execution by ID
def deleteExecution(execution_id):
    url = 'https://'+ RUNDECKSERVER +':4443/api/12/execution/'+execution_id
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.delete(url, headers=headers, verify=False)    

    
def isOlderThan90days(execution_date, today):
    if ((today - execution_date) > MILISECONDS_IN_THREE_MONTHS):
        return True
    return False

def check(execid_dates):
    for exec_id, exec_date in execid_dates.iteritems():
    	if isOlderThan90days (int(exec_date), TODAY):
    	    getExecutionDate(exec_id)
    	       
jobids = getJobIDs(listJobsForProject(PROJECT_NAME))
for jobid in jobids:
    check(getExecutionDate(getExecutionsForAJob(jobid)))<commit_msg>Now, even better. No need to specify the project anymore. Will take ALL the projects directly from the API<commit_after>import requests
import xml.etree.ElementTree as ET
import time

API_KEY='myAPIkeyfglIdHkIuRerDBPhgt'
RUNDECKSERVER = 'https://yourrundeckserver.com'

MILISECONDS_IN_THREE_MONTHS = 7889000000
TODAY = int(round(time.time() * 1000))

# API call to get the list of the existing projects on the server.
def listProjects():
    url = 'https://'+ RUNDECKSERVER +':4443/api/1/projects'
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.get(url, headers=headers, verify=False)
    return r.text
    
# Returns list of all the project names
def getProjectNames(projectsinfo_xml):
    project_names = []
    root = ET.fromstring(projectsinfo_xml)
    for projects in root:	
        for name in projects.findall('project'):
            project_names.append(name.find('name').text)
    return project_names   

# API call to get the list of the jobs that exist for a project.
def listJobsForProject(project_mame):
    url = 'https://'+ RUNDECKSERVER +':4443/api/1/jobs'
    payload = { 'project':  project_mame }
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.get(url, params=payload, headers=headers, verify=False)
    return r.text

# Returns list of all the jobids
def getJobIDs(jobsinfo_xml):
    job_ids = []
    root = ET.fromstring(jobsinfo_xml)	
    for jobs in root:
        for job in jobs:
            job_ids.append(job.attrib['id'])
    return job_ids

# API call to get the list of the executions for a Job.      
def getExecutionsForAJob(job_id):
    url = 'https://'+ RUNDECKSERVER +':4443/api/1/job/'+job_id+'/executions'
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.get(url, headers=headers, verify=False)
    return r.text

# Returns a dict {'execution_id01': 'execution_date01', 'execution_id02': 'execution_date02', ... }
def getExecutionDate(executionsinfo_xml):
    execid_dates = {}
    root = ET.fromstring(executionsinfo_xml)
    for executions in root:     
        for execution in executions.findall('execution'):
            execution_id = execution.get('id')
            for date in execution.findall('date-ended'):
                execution_date = date.get('unixtime')
    	    execid_dates[execution_id] = execution_date
    return execid_dates
       
#API call to delete an execution by ID
def deleteExecution(execution_id):
    url = 'https://'+ RUNDECKSERVER +':4443/api/12/execution/'+execution_id
    headers = {'Content-Type': 'application/json','X-RunDeck-Auth-Token': API_KEY }
    r = requests.delete(url, headers=headers, verify=False)    

    
def isOlderThan90days(execution_date, today):
    if ((today - execution_date) > MILISECONDS_IN_THREE_MONTHS):
        return True
    return False

def checkDeletion(execid_dates):
    for exec_id, exec_date in execid_dates.iteritems():
    	if isOlderThan90days (int(exec_date), TODAY):
    	    deleteExecution(exec_id)
    	      
projects = getProjectNames(listProjects())
for project in projects:
    jobids = getJobIDs(listJobsForProject(project))
    for jobid in jobids:
        checkDeletion(getExecutionDate(getExecutionsForAJob(jobid))) 
{'fraction_non_alphanumeric': 0.11404109589041096, 'fraction_numerical': 0.01523972602739726, 'mean_word_length': 3.7257281553398056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1851498', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1883, 'n_words': 445}