|
| 1 | +import aw_client |
| 2 | +from aw_transform.filter_period_intersect import _intersecting_eventpairs |
| 3 | + |
| 4 | + |
| 5 | +def main(): |
| 6 | + aw = aw_client.ActivityWatchClient(testing=True) |
| 7 | + buckets = aw.get_buckets() |
| 8 | + print(f"Buckets: {buckets.keys()}") |
| 9 | + src_id = input("Source bucket ID: ") |
| 10 | + dest_id = input("Destination bucket ID: ") |
| 11 | + |
| 12 | + src_events = aw.get_events(src_id) |
| 13 | + print(f"✓ src events: {len(src_events)}") |
| 14 | + dest_events = aw.get_events(dest_id) |
| 15 | + print(f"✓ dest events: {len(dest_events)}") |
| 16 | + |
| 17 | + print("Checking overlap") |
| 18 | + overlaps = list(_intersecting_eventpairs(src_events, dest_events)) |
| 19 | + if overlaps: |
| 20 | + print("Buckets had overlap, can't safely merge") |
| 21 | + exit(1) |
| 22 | + print("No overlap detected, continuing...") |
| 23 | + |
| 24 | + print("You want to merge these two buckets:") |
| 25 | + print(f" - {src_id}") |
| 26 | + print(f" - {dest_id}") |
| 27 | + print( |
| 28 | + "WARNING: you should backup/export the buckets before attempting this operation" |
| 29 | + ) |
| 30 | + if input("Does that look right? (y/n): ") != "y": |
| 31 | + print("Aborting") |
| 32 | + exit(1) |
| 33 | + |
| 34 | + # src_b = buckets[src_id] |
| 35 | + # dest_b = buckets[dest_id] |
| 36 | + # print(src_b) |
| 37 | + # print(dest_b) |
| 38 | + |
| 39 | + print("Inserting source events into destination bucket...") |
| 40 | + # print("SKIPPING DUE TO BROKEN OVERLAP CHECK") |
| 41 | + aw.insert_events(dest_id, src_events) |
| 42 | + |
| 43 | + print("Operation complete") |
| 44 | + if input("Do you want to delete the source bucket? (y/n): ") == "y": |
| 45 | + print("Deleting source bucket") |
| 46 | + print("SKIPPING DUE TO BROKEN OVERLAP CHECK") |
| 47 | + # aw.delete_bucket(src_id) |
| 48 | + # print("Bucket deleted") |
| 49 | + |
| 50 | + print("Exiting") |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + main() |
0 commit comments