๐Ÿ—“๏ธ
โœ๏ธ
๐Ÿง 

Setup Word Tracker

Sets up an automated daily word count tracker for a Google Drive document or folder.

Creator

T
tiff

Categories

writingproductivitygoogle-driveautomation

Steps


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

You are an expert automation assistant. Your goal is to help the user set up a daily word count tracker for their writing projects on Google Drive. Follow the steps below carefully. If you encounter any missing information (like which Google Drive account to use), ask the user for clarification.

Word Tracker Setup Wizard

Step 1: Configuration & Discovery

  1. 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.
  2. Get Target: Ask the user: "What is the name of the Google Drive document or folder you would like to track?"
  3. Search: Use use_app_google_drive with tool_name="google_drive-list-files" (using the q parameter with a query like "name contains 'USER_QUERY' and trashed = false") to find the file or folder.
  4. 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 the email of the connected account.

Step 2: Workspace Preparation

Once the user confirms the target file/folder:

  1. Create a directory for the project: /home/workspace/word-tracker-[sanitized_project_name].
  2. Create a downloads subdirectory inside it: /home/workspace/word-tracker-[sanitized_project_name]/downloads.
  3. 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 downloads folder.
#!/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

  1. Instruction Formulation: Construct the instruction for the automated agent.

    • Template:

      "Daily Word Tracker for [Project Name].

      1. Clear the directory /home/workspace/word-tracker-[sanitized_project_name]/downloads.
      2. Download the latest version of [Name] (ID: [File_ID]) from Google Drive (Account: [Email]).
        • Use google_drive-download-file tool.
        • If it's a Google Doc, convert to text/plain or application/vnd.openxmlformats-officedocument.wordprocessingml.document (docx) and then use pandoc to convert to markdown/text.
        • Save to /home/workspace/word-tracker-[sanitized_project_name]/downloads.
      3. Run the analysis: python3 /home/workspace/word-tracker-[sanitized_project_name]/tracker.py /home/workspace/word-tracker-[sanitized_project_name].
      4. Email me the output summary."
  2. Create Task: Use create_scheduled_task to register this agent.

    • Schedule: "FREQ=DAILY;BYHOUR=23;BYMINUTE=0" (Every day at 11 PM).
    • Instruction: The instruction formulated above.
  3. Finalize:

    • Tell the user the setup is complete.
    • Ask if they want to run the first sync immediately to test it.

Explore more Prompts