-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
83 lines (63 loc) · 2.3 KB
/
agent.py
File metadata and controls
83 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Automation Agent - Main Entry Point
-----------------------------------
Orchestrates the workflow: Spreadsheet -> Agent -> Web Search -> Result
This agent reads rows from an Excel spreadsheet, processes each row,
performs a web search for the name/company, and prints the results.
"""
import sys
from pathlib import Path
from spreadsheet_reader import get_rows_as_dicts, build_search_query
from web_search import search, format_search_result
def run_agent(spreadsheet_path: str = "data.xlsx") -> None:
"""
Run the automation agent workflow.
Workflow:
1. Read rows from the spreadsheet
2. For each row, build a search query (name + company)
3. Perform web search for each query
4. Print results to console
Args:
spreadsheet_path: Path to the Excel spreadsheet
"""
print("=" * 60)
print(" PYTHON AUTOMATION AGENT - Data Collection Workflow")
print("=" * 60)
print()
# Step 1: Read spreadsheet
print("[1] Reading spreadsheet:", spreadsheet_path)
try:
rows = get_rows_as_dicts(spreadsheet_path)
except FileNotFoundError as e:
print(f" ERROR: {e}")
print(" Please ensure data.xlsx exists in the project directory.")
sys.exit(1)
print(f" Found {len(rows)} rows to process.")
print()
# Step 2 & 3 & 4: Process each row
print("[2] Processing rows (spreadsheet -> agent -> web search -> result)")
print("-" * 60)
for i, row in enumerate(rows, start=1):
row_id = row.get("id", i)
name = row.get("name", "")
company = row.get("company", "")
# Build search query from name and company
query = build_search_query(row)
print(f"\nRow {i} (id={row_id}): {name} @ {company}")
print(f" Search query: \"{query}\"")
if not query:
print(" [SKIP] No search query (missing name and company)")
continue
# Perform web search
result = search(query)
# Print result
print(format_search_result(result))
print()
print("-" * 60)
print("[3] Workflow complete. All rows processed.")
print("=" * 60)
if __name__ == "__main__":
# Default to data.xlsx in the script's directory
script_dir = Path(__file__).parent
data_file = script_dir / "data.xlsx"
run_agent(str(data_file))