-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_scraper.py
More file actions
56 lines (43 loc) · 1.67 KB
/
cli_scraper.py
File metadata and controls
56 lines (43 loc) · 1.67 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
import asyncio
import os
import sys
from dotenv import load_dotenv
# Add current directory to path so imports work
sys.path.append(os.getcwd())
# Load environment variables
load_dotenv()
from backend.app.services.legal_scraper import legal_scraper
async def main():
print("=== LegalAI Scraper Tool (Firecrawl Enabled) ===")
# Check for Firecrawl Key
api_key = os.getenv("FIRECRAWL_API_KEY")
if api_key:
print(f"✅ Firecrawl API Key found: {api_key[:5]}... (Will use Firecrawl)")
else:
print("⚠️ Firecrawl API Key NOT found. (Will fallback to basic scraper)")
print(" To enable Firecrawl, add FIRECRAWL_API_KEY=fc-xxx to your .env file")
while True:
print("\n------------------------------------------------")
url = input("Enter URL to scrape (or 'q' to quit): ").strip()
if url.lower() in ('q', 'quit', 'exit'):
break
if not url:
continue
print(f"\nProcessing: {url}...")
try:
# Call the scraper
result = await legal_scraper.scrape_and_ingest(url, category="Manual Input")
if result.get("status") == "success":
print("\n✅ Success!")
print(f"Law ID: {result.get('law_id')}")
print("Data has been saved to the database.")
else:
print("\n❌ Error:")
print(result.get("message"))
except Exception as e:
print(f"\n❌ Unexpected Error: {e}")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nExiting...")