75a0a3fde7
- Added `get_latest_email_date()` function in `database.py` to retrieve the most recent email date for a given account and folder. - Enhanced `fetch_folder_emails()` in `zoho_client.py` to intelligently determine the start date for fetching emails based on the latest email date in the database. - Introduced `analyze_and_update_threads_async()` for asynchronous analysis of email threads, allowing concurrent processing. - Created a synchronous wrapper `analyze_and_update_threads()` for easier integration. - Updated `fetch_emails()` to support database session and account email parameters. - Added comprehensive documentation in `AI_ANALYSIS_GUIDE.md` detailing the new AI analysis functionality. - Implemented tests for the new features, including `test_fetch_with_db.py`, `test_ai_analysis.py`, and `test_single_analysis.py`. - Added error handling and logging improvements throughout the codebase.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to demonstrate the modified fetch_folder_emails function
|
|
that uses database dates for intelligent email fetching.
|
|
"""
|
|
|
|
from src.database import SessionLocal, get_latest_email_date
|
|
from src.zoho_client import ZohoClient
|
|
|
|
|
|
def test_fetch_with_database():
|
|
"""Test the modified fetch function with database integration."""
|
|
|
|
# Create database session
|
|
db = SessionLocal()
|
|
|
|
try:
|
|
# Create Zoho client
|
|
client = ZohoClient()
|
|
|
|
# Example account email (replace with actual)
|
|
account_email = client.email
|
|
|
|
print("=== Testing fetch_folder_emails with database integration ===")
|
|
|
|
# Check what's the latest date in database
|
|
latest_date = get_latest_email_date(db, account_email, "INBOX")
|
|
print(f"Latest email date in database: {latest_date}")
|
|
|
|
# Fetch emails using the new function
|
|
emails = client.fetch_folder_emails(
|
|
folder="INBOX",
|
|
max_results=10,
|
|
days_back=30, # Fallback if no database date
|
|
db_session=db,
|
|
account_email=account_email,
|
|
)
|
|
|
|
print(f"Fetched {len(emails)} emails")
|
|
|
|
# Display first few emails
|
|
for i, email in enumerate(emails[:3]):
|
|
print(f"\nEmail {i + 1}:")
|
|
print(f" Subject: {email.get('subject', 'No subject')}")
|
|
print(f" From: {email.get('from', 'Unknown')}")
|
|
print(f" Date: {email.get('date', 'Unknown')}")
|
|
|
|
client.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_fetch_with_database()
|