title: Setup Word Tracker description: Sets up an automated daily word count tracker for a Google Drive document or folder. tags:
- writing
- productivity
- google-drive
- automation tool: true
Word Tracker Setup Wizard
Step 1: Configuration & Discovery
- Check Google Drive: Verify the user has Google Drive connected by running
list_app_tools(app_slug="google_drive").- If not connected, guide them to connect it in Settings > Integrations.
- Get Target: Ask the user: "What is the name of the Google Drive document or folder you would like to track?"
- Search: Use
use_app_google_drivewithtool_name="google_drive-list-files"(using theqparameter with a query like"name contains 'USER_QUERY' and trashed = false") to find the file or folder. - Confirm: Present the options found (with their Names and IDs) and ask the user to confirm which one is correct.
- Important: Note down the
file_id,name, and theemailof the connected account.
- Important: Note down the
Step 2: Workspace Preparation
Once the user confirms the target file/folder:
- Create a directory for the project:
/home/workspace/word-tracker-[sanitized_project_name]. - Create a
downloadssubdirectory inside it:/home/workspace/word-tracker-[sanitized_project_name]/downloads. - Create the analysis script by writing the following code to tracker.py.
- Note: This script is generic and calculates stats based on the files found in the
downloadsfolder.
- Note: This script is generic and calculates stats based on the files found in the
#!/usr/bin/env python3 """ Word Tracker - Calculate word counts from synced text files """ import json import sys import argparse from pathlib import Path from datetime import datetime, timezone def count_words_in_file(file_path: Path) -> int: """Count words in a text file""" try: text = file_path.read_text(encoding='utf-8', errors='ignore') # Simple whitespace splitting words = text.split() return len(words) except Exception as e: print(f"Error counting words in {file_path}: {e}") return 0 def load_previous_counts(tracking_file: Path) -> dict: """Load the most recent word counts from tracking file""" if not tracking_file.exists(): return {} try: with open(tracking_file, 'r') as f: lines = f.readlines() if lines: # Find the last valid JSON line for line in reversed(lines): if line.strip(): return json.loads(line).get('counts', {}) except Exception as e: print(f"Error loading previous counts: {e}") return {} def save_counts(tracking_file: Path, counts: dict, stats: dict): """Append current counts and stats to tracking file""" entry = { 'timestamp': datetime.now(timezone.utc).isoformat(), 'date': datetime.now().strftime('%Y-%m-%d'), 'counts': counts, 'stats': stats } with open(tracking_file, 'a') as f: f.write(json.dumps(entry) + '\n') def calculate_stats(data_dir: Path): """Calculate word count statistics from synced files""" downloads_dir = data_dir / "downloads" tracking_file = data_dir / "data.jsonl" if not downloads_dir.exists(): print(f"Downloads directory not found: {downloads_dir}") return # Load previous counts previous_counts = load_previous_counts(tracking_file) # Count words in all text files in downloads directory current_counts = {} total_words = 0 # Support multiple text extensions files = [] for ext in ['*.txt', '*.md', '*.markdown']: files.extend(list(downloads_dir.glob(f"**/{ext}"))) if not files: print("No files found in downloads directory.") return print(f"๐ Analyzing {len(files)} file(s)...") for file_path in files: # Use relative path as key rel_path = str(file_path.relative_to(downloads_dir)) word_count = count_words_in_file(file_path) current_counts[rel_path] = word_count total_words += word_count print(f" {rel_path}: {word_count:,} words") # Calculate daily changes words_added = 0 words_removed = 0 new_files = [] for path, current_count in current_counts.items(): if path in previous_counts: diff = current_count - previous_counts[path] if diff > 0: words_added += diff elif diff < 0: words_removed += abs(diff) else: new_files.append(path) words_added += current_count # Treat new files as added words # Check for deleted files (files present in previous but not current) for path, prev_count in previous_counts.items(): if path not in current_counts: words_removed += prev_count print(f" (File removed: {path})") # Calculate net change net_change = words_added - words_removed # Prepare stats stats = { 'total_words': total_words, 'words_added': words_added, 'words_removed': words_removed, 'net_change': net_change, 'file_count': len(files), 'new_files': new_files } # Save to tracking file save_counts(tracking_file, current_counts, stats) # Print summary print(f"\n๐ Daily Summary") print(f"{'='*50}") print(f"Total words: {total_words:,}") print(f"Words added: +{words_added:,}") if words_removed > 0: print(f"Words removed: -{words_removed:,}") print(f"Net change: {net_change:+,}") if new_files: print(f"\n๐ New files detected:") for f in new_files: print(f" - {f}") print(f"\nโ Tracking data saved to {tracking_file}") if __name__ == "__main__": parser = argparse.ArgumentParser(description='Word Tracker') parser.add_argument('dir', type=str, help='Project directory containing downloads/ and where data.jsonl will be saved') args = parser.parse_args() calculate_stats(Path(args.dir))
Step 3: Scheduling
-
Instruction Formulation: Construct the instruction for the automated agent.
- Template:
"Daily Word Tracker for [Project Name].
- Clear the directory
/home/workspace/word-tracker-[sanitized_project_name]/downloads. - Download the latest version of [Name] (ID:
[File_ID]) from Google Drive (Account:[Email]).- Use
google_drive-download-filetool. - If it's a Google Doc, convert to
text/plainorapplication/vnd.openxmlformats-officedocument.wordprocessingml.document(docx) and then usepandocto convert to markdown/text. - Save to
/home/workspace/word-tracker-[sanitized_project_name]/downloads.
- Use
- Run the analysis:
python3 /home/workspace/word-tracker-[sanitized_project_name]/tracker.py /home/workspace/word-tracker-[sanitized_project_name]. - Email me the output summary."
- Clear the directory
- Template:
-
Create Task: Use
create_scheduled_taskto register this agent.- Schedule: "FREQ=DAILY;BYHOUR=23;BYMINUTE=0" (Every day at 11 PM).
- Instruction: The instruction formulated above.
-
Finalize:
- Tell the user the setup is complete.
- Ask if they want to run the first sync immediately to test it.