-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (66 loc) · 2.23 KB
/
Copy pathmain.py
File metadata and controls
82 lines (66 loc) · 2.23 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
import os
from dotenv import load_dotenv
from agent import run_agent
from batch import run_batch
from history import print_history
load_dotenv()
def banner():
print("\n" + "="*55)
print(" 🏢 AI Business Listing Agent v2.0")
print(" Powered by Serper + Gemini + Google Sheets")
print("="*55)
print(" Commands:")
print(" → best cafes in New York (single search)")
print(" → batch (run many at once)")
print(" → history (view past searches)")
print(" → quit (exit)")
print("="*55 + "\n")
def get_sheet_url():
url = os.getenv("SPREADSHEET_URL")
if not url:
print("⚠️ No SPREADSHEET_URL in .env! Please add it.")
exit()
return url
def handle_batch(sheet_url: str):
print("\n 📦 BATCH MODE")
print(" Enter one search per line.")
print(" Type 'done' when finished.\n")
queries = []
while True:
q = input(f" Query {len(queries)+1}: ").strip()
if q.lower() == "done":
break
if q:
queries.append(q)
if not queries:
print(" ⚠️ No queries entered.\n")
return
print(f"\n ✅ {len(queries)} queries queued:")
for i, q in enumerate(queries, 1):
print(f" {i}. {q}")
confirm = input("\n Start batch? (y/n): ").strip().lower()
if confirm == "y":
run_batch(queries, sheet_url)
else:
print(" Batch cancelled.\n")
def main():
banner()
sheet_url = get_sheet_url()
print(f" 📋 Sheet: {sheet_url}\n")
while True:
query = input("🔎 Command or search: ").strip()
if not query:
continue
elif query.lower() in ["quit", "exit", "q"]:
print("\n👋 Bye! Your data is saved in Google Sheets.\n")
break
elif query.lower() == "history":
print_history()
elif query.lower() == "batch":
handle_batch(sheet_url)
else:
url = run_agent(query, sheet_url)
if url:
print(f"\n 🔗 Sheet: {url}\n")
if __name__ == "__main__":
main()