diff --git a/wizard-work/spark/scratch_word_counter.py b/wizard-work/spark/scratch_word_counter.py new file mode 100644 index 0000000..2ca3fbd --- /dev/null +++ b/wizard-work/spark/scratch_word_counter.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +"""Count words in all text files in the scratch directory and output JSON report.""" +import os +import json +from pathlib import Path + +SCRATCH_DIR = "/root/.hermes/profiles/spark/cache/scratch" +OUTPUT_FILE = "/root/.hermes/wizard-outputs/spark/word_count_report.json" + +def count_words_in_file(filepath): + """Count words in a file, return 0 if unreadable.""" + try: + with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: + content = f.read() + return len(content.split()) + except Exception: + return 0 + +def main(): + results = [] + total_words = 0 + + scratch_path = Path(SCRATCH_DIR) + if scratch_path.exists(): + for filepath in sorted(scratch_path.iterdir()): + if filepath.is_file(): + word_count = count_words_in_file(filepath) + total_words += word_count + results.append({ + "file": filepath.name, + "word_count": word_count + }) + + report = { + "scratch_directory": SCRATCH_DIR, + "files_processed": len(results), + "total_words": total_words, + "files": results + } + + with open(OUTPUT_FILE, 'w') as f: + json.dump(report, f, indent=2) + + print(f"Word count report written to {OUTPUT_FILE}") + print(f"Files: {len(results)}, Total words: {total_words}") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/wizard-work/spark/word_count_report.json b/wizard-work/spark/word_count_report.json new file mode 100644 index 0000000..24f1eec --- /dev/null +++ b/wizard-work/spark/word_count_report.json @@ -0,0 +1,27 @@ +{ + "scratch_directory": "/root/.hermes/profiles/spark/cache/scratch", + "files_processed": 5, + "total_words": 789, + "files": [ + { + "file": ".last_prune", + "word_count": 0 + }, + { + "file": "hermes-snap-18c65962e510.sh", + "word_count": 261 + }, + { + "file": "hermes-snap-42e725078645.sh", + "word_count": 261 + }, + { + "file": "hermes-snap-717571bc4904.sh", + "word_count": 261 + }, + { + "file": "tmpnx0d8oia.json", + "word_count": 6 + } + ] +} \ No newline at end of file