|
| 1 | +""" |
| 2 | +Cleans up messy test/demo artifacts. |
| 3 | +- Delete empty Slices with <1k Items |
| 4 | +- Delete Slices with name like "test" (often repeated demo flows) |
| 5 | +""" |
| 6 | +import argparse |
| 7 | +import logging |
| 8 | + |
| 9 | +import nucleus |
| 10 | + |
| 11 | +log = logging.getLogger() |
| 12 | +log.setLevel(logging.INFO) |
| 13 | + |
| 14 | + |
| 15 | +def cleanup_slices(api_key, dataset_id): |
| 16 | + client = nucleus.NucleusClient(api_key) |
| 17 | + |
| 18 | + dataset = client.get_dataset(dataset_id) |
| 19 | + |
| 20 | + log.info("======\nChecking for Slices to delete\n======") |
| 21 | + for slc_id in dataset.slices: |
| 22 | + slc = client.get_slice(slc_id) |
| 23 | + slc_info = slc.info() |
| 24 | + slc_name = slc_info["name"] |
| 25 | + |
| 26 | + if any(kw in slc_name.lower() for kw in ["test", "night", "police", "truck"]): |
| 27 | + log.info("Deleting Slice '%s' because it contains night/police/truck keyword. Slice id: %s", |
| 28 | + slc_name, slc_id) |
| 29 | + client.delete_slice(slc_id) |
| 30 | + |
| 31 | + if len(slc_info['dataset_items']) < 1000: |
| 32 | + log.info("Deleting Slice '%s' because it contains fewer than 1000 items. Slice id: %s", |
| 33 | + slc_name, slc_id) |
| 34 | + client.delete_slice(slc_id) |
| 35 | + |
| 36 | + |
| 37 | +if __name__ == "__main__": |
| 38 | + parser = argparse.ArgumentParser() |
| 39 | + parser.add_argument('api_key', type=str) |
| 40 | + parser.add_argument('dataset_id', type=str) |
| 41 | + args = parser.parse_args() |
| 42 | + |
| 43 | + cleanup_slices(args.api_key, args.dataset_id) |
0 commit comments