mirror of
https://github.com/nicholaswilde/recipes.git
synced 2026-08-18 02:54:22 +00:00
feat: add script and skill to deduplicate zensical.toml
This commit is contained in:
18
.agents/skills/dedupe-zensical.md
Normal file
18
.agents/skills/dedupe-zensical.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
name: dedupe-zensical
|
||||
description: Remove duplicate array entries in the zensical.toml configuration file.
|
||||
---
|
||||
|
||||
# Dedupe Zensical Skill
|
||||
|
||||
This skill removes duplicate array entries in `zensical.toml` (such as duplicate recipe links under menu categories like `Sides = [...]`).
|
||||
|
||||
## Usage
|
||||
|
||||
When a user requests to deduplicate or remove duplicates from `zensical.toml`, you should simply run the following task:
|
||||
|
||||
```bash
|
||||
task dedupe-zensical
|
||||
```
|
||||
|
||||
This task executes the `scripts/dedupe_zensical.py` Python script, which parses `zensical.toml`, finds exact string duplicates within any array blocks (lines between `[` and `]`), removes them, and overwrites the file in place. It prints the number of duplicates removed.
|
||||
@ -260,8 +260,12 @@ tasks:
|
||||
sops --decrypt --input-type json --output-type json --output settings.json settings.json.enc
|
||||
fi
|
||||
|
||||
dedupe-zensical:
|
||||
desc: Remove duplicate array entries in zensical.toml
|
||||
cmds:
|
||||
- uv run python3 scripts/dedupe_zensical.py
|
||||
|
||||
default:
|
||||
cmds:
|
||||
- task -a
|
||||
silent: true
|
||||
|
||||
|
||||
47
scripts/dedupe_zensical.py
Executable file
47
scripts/dedupe_zensical.py
Executable file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
|
||||
def dedupe_zensical(filepath="zensical.toml"):
|
||||
if not os.path.exists(filepath):
|
||||
print(f"Error: {filepath} not found.")
|
||||
return
|
||||
|
||||
with open(filepath, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
new_lines = []
|
||||
seen_in_section = set()
|
||||
in_array = False
|
||||
removed_count = 0
|
||||
|
||||
for line in lines:
|
||||
# Detect the start of an array section (e.g., `Sides = [`)
|
||||
if "=" in line and "[" in line and "]" not in line:
|
||||
in_array = True
|
||||
seen_in_section = set()
|
||||
new_lines.append(line)
|
||||
continue
|
||||
elif "]" in line and in_array:
|
||||
in_array = False
|
||||
new_lines.append(line)
|
||||
continue
|
||||
|
||||
if in_array and "{" in line and "}" in line:
|
||||
trimmed = line.strip()
|
||||
if trimmed in seen_in_section:
|
||||
removed_count += 1
|
||||
continue
|
||||
seen_in_section.add(trimmed)
|
||||
|
||||
new_lines.append(line)
|
||||
|
||||
if removed_count > 0:
|
||||
with open(filepath, "w") as f:
|
||||
f.writelines(new_lines)
|
||||
print(f"Successfully removed {removed_count} duplicate entries from {filepath}.")
|
||||
else:
|
||||
print(f"No duplicate entries found in {filepath}.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
dedupe_zensical()
|
||||
Reference in New Issue
Block a user