Buckets:
| #!/usr/bin/env python3 | |
| """ | |
| R CLI - Workflow Automation Example | |
| Shows how to chain multiple skills together for complex tasks. | |
| """ | |
| from r_cli.core.agent import Agent | |
| def analyze_csv_and_report(csv_path: str, output_pdf: str): | |
| """ | |
| Workflow: Analyze CSV data and generate a PDF report. | |
| 1. Run SQL queries on the CSV | |
| 2. Generate summary statistics | |
| 3. Create a PDF report | |
| """ | |
| agent = Agent() | |
| agent.load_skills() | |
| # Step 1: Get basic stats | |
| print("Step 1: Analyzing data...") | |
| stats = agent.run_skill_directly( | |
| "sql", | |
| query="SELECT COUNT(*) as total_rows FROM data", | |
| csv=csv_path, | |
| ) | |
| # Step 2: Get column info | |
| columns = agent.run_skill_directly( | |
| "sql", | |
| query="SELECT * FROM data LIMIT 1", | |
| csv=csv_path, | |
| ) | |
| # Step 3: Generate report content | |
| report_content = f"""# Data Analysis Report | |
| ## Overview | |
| - **File**: {csv_path} | |
| - **Statistics**: {stats} | |
| ## Sample Data | |
| ``` | |
| {columns} | |
| ``` | |
| ## Generated by R CLI | |
| This report was automatically generated using the SQL and PDF skills. | |
| """ | |
| # Step 4: Create PDF | |
| print("Step 2: Generating PDF report...") | |
| result = agent.run_skill_directly( | |
| "pdf", | |
| content=report_content, | |
| output=output_pdf, | |
| title="Data Analysis Report", | |
| ) | |
| print(f"Report saved to: {output_pdf}") | |
| return result | |
| def backup_and_archive(source_dir: str, backup_name: str): | |
| """ | |
| Workflow: Create a backup archive with git info. | |
| 1. Get git status | |
| 2. Create archive | |
| 3. Log the backup | |
| """ | |
| agent = Agent() | |
| agent.load_skills() | |
| # Step 1: Get git info | |
| print("Getting git status...") | |
| git_info = agent.run_skill_directly( | |
| "git", | |
| action="status", | |
| path=source_dir, | |
| ) | |
| # Step 2: Create archive | |
| print("Creating archive...") | |
| archive_result = agent.run_skill_directly( | |
| "archive", | |
| action="create", | |
| source=source_dir, | |
| output=f"{backup_name}.zip", | |
| format="zip", | |
| ) | |
| # Step 3: Get timestamp | |
| timestamp = agent.run_skill_directly( | |
| "datetime", | |
| action="now", | |
| format="%Y-%m-%d %H:%M:%S", | |
| ) | |
| print(f"Backup created: {backup_name}.zip at {timestamp}") | |
| print(f"Git status: {git_info[:100]}...") | |
| return archive_result | |
| def scrape_and_summarize(url: str): | |
| """ | |
| Workflow: Scrape a webpage and create a summary. | |
| 1. Fetch webpage content | |
| 2. Extract text | |
| 3. Save to markdown | |
| """ | |
| agent = Agent() | |
| agent.load_skills() | |
| # Step 1: Fetch page | |
| print(f"Fetching {url}...") | |
| content = agent.run_skill_directly( | |
| "web", | |
| action="fetch", | |
| url=url, | |
| ) | |
| # Step 2: Save as markdown | |
| print("Saving content...") | |
| result = agent.run_skill_directly( | |
| "fs", | |
| action="write", | |
| path="scraped_content.md", | |
| content=f"# Scraped from {url}\n\n{content[:2000]}...", | |
| ) | |
| print("Content saved to scraped_content.md") | |
| return result | |
| if __name__ == "__main__": | |
| print("R CLI Workflow Examples") | |
| print("=" * 40) | |
| print("\nAvailable workflows:") | |
| print("1. analyze_csv_and_report(csv_path, output_pdf)") | |
| print("2. backup_and_archive(source_dir, backup_name)") | |
| print("3. scrape_and_summarize(url)") | |
| print("\nExample:") | |
| print(' analyze_csv_and_report("data.csv", "report.pdf")') | |
Xet Storage Details
- Size:
- 3.41 kB
- Xet hash:
- ad01f7ef1da092f355cd072846a567aa5f7cf2d4ec0b3afde7d156bbeb10c481
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.