getcore402.com
← Back to Blog Developer Pack $1.00
Case Study

How to Automate Folder Cleanup in a Blink with Core402

Tired of manual file sorting and bloated scripts? Discover how to delegate your daily maintenance chores to our API with a simple Python snippet.


In your digital workspaces, you accumulate temporary folders: reports, drafts, screenshots, or maintenance logs. Over time, these folders get cluttered. Sorting and cleaning them manually takes precious time, and writing custom scripts from scratch for every task is tedious.

At Core402, we know that automation should simplify your life, not complicate it. That is why we invite you to discover through this practical case study how to delegate this chore to our API with complete ease.

💡 The Solution: The Intelligent Courier

Imagine you want to clean up a temporary files folder containing items older than 30 days. Instead of writing dozens of complex lines of code, we streamline the operation using a simple principle, comparable to sending a parcel via courier:

  1. Your script prepares the parcel: It gathers essential information (where to go, what action to perform) into a standardized format called the payload.
  2. The courier delivers the request: The script transmits this parcel securely to the Core402 API using your authentication key (retrieved beforehand via your purchase from the [Get API Key] buttons).
  3. The system executes and replies: The API handles all the sorting logic in the background and returns a clear report to you.

What does this "parcel" (the payload) look like?

To ensure the system understands exactly what you expect, the request body is structured cleanly in JSON format:

{  "target": "/opt/core402/data/temp_files",  "action": "cleanup_and_archive",  "options": {    "max_age_days": 30,    "compress": true,    "archive_format": "zip"  }}
  • Target (target): The precise path where action must be taken.
  • Action (action): The assigned command (here, cleanup and archive).
  • Options (options): The rules of the game (target files older than 30 days and compress them into a ZIP archive).

The Code in Action

Thanks to our lightweight client, we explain how to trigger this automation in just a few lines of Python:

import os
import requests
from dotenv import load_dotenv

# 1. Load your configuration securely
load_dotenv()
API_GATEWAY_URL = os.getenv("API_GATEWAY_URL", "http://localhost:3000/v1/automate")
API_KEY = os.getenv("CORE402_API_KEY")

# 2. Prepare your request (payload & access headers)
headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
payload = {
    "target": "/opt/core402/data/temp_files",
    "action": "cleanup_and_archive",
    "options": {"max_age_days": 30, "compress": True}
}

# 3. Send the request to the Core402 API
response = requests.post(API_GATEWAY_URL, json=payload, headers=headers)

if response.status_code == 200:
    print("[+] Cleanup task executed successfully!")
    print(response.json())
else:
    print(f"[x] Error: {response.status_code}")

Why is this useful?

By adopting this approach, we empower you to break free from repetitive tasks and thus save precious time. No need to reinvent the wheel: Core402 centralizes intelligence so you can focus on what truly matters.

Get API Key ($1.00 Developer Pack)