Spaces:
Build error
Build error
| import sys | |
| import time | |
| import logging | |
| from datetime import datetime | |
| from config import Config | |
| from pdf_parser import extract_text_from_pdf, parse_email_thread, get_days_without_account | |
| from email_watcher import check_for_new_fos_email | |
| from notifier import send_telegram_message, send_email_notification | |
| from scheduler import start_scheduler | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| def print_banner(): | |
| print(""" | |
| ββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β π₯ Complaint Tracker Suite β v2.0 β | |
| β Monitoring your FOS case 24/7 β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββ | |
| """) | |
| def generate_initial_report(): | |
| """Produce a full report from the PDF and display it.""" | |
| text = extract_text_from_pdf() | |
| emails = parse_email_thread(text) | |
| days = get_days_without_account(text) | |
| print(f"\nπ REPORT β {datetime.now().strftime('%Y-%m-%d %H:%M')}") | |
| print(f"Days without a functional account: {days}") | |
| print(f"Total emails in thread: {len(emails)}") | |
| if emails: | |
| last = emails[-1] | |
| print(f"Last email from: {last['from']} on {last['date']}") | |
| print(f"Subject: {last['subject']}") | |
| print("Preview:", last['body'][:200].replace('\n', ' '), "...") | |
| else: | |
| print("No emails found.") | |
| # Also send a startup notification via Telegram | |
| send_telegram_message(f"π Complaint Tracker started.\nDays without account: {days}") | |
| def main(): | |
| print_banner() | |
| # 1. Run initial report | |
| generate_initial_report() | |
| # 2. Send a daily summary to landlord immediately (optional) | |
| # You can also let the scheduler handle it. | |
| # 3. Start the background scheduler | |
| scheduler = start_scheduler() | |
| # 4. Keep the main thread alive, or provide a simple CLI menu | |
| print("\nPress Ctrl+C to stop.") | |
| try: | |
| while True: | |
| time.sleep(1) | |
| except KeyboardInterrupt: | |
| print("\nShutting down scheduler...") | |
| scheduler.shutdown() | |
| print("Goodbye.") | |
| sys.exit(0) | |
| if __name__ == "__main__": | |
| main() |