import sys with open('fotograf-de-scraper/backend/main.py', 'r') as f: content = f.read() old_code = """ # 1. Get emails that have ALREADY purchased anything (in ANY job we have in DB) purchased_emails = set() if exclude_purchased_emails: from sqlalchemy import or_ # We look globally across the whole job_participants table purchased_results = db.query(JobParticipant.email_eltern).filter( or_(JobParticipant.has_orders == 1, JobParticipant.digital_package_ordered == 1), JobParticipant.email_eltern != "", JobParticipant.email_eltern != None ).all() purchased_emails = {r[0].lower() for r in purchased_results} logger.info(f"Task {task_id}: Found {len(purchased_emails)} unique emails with existing purchases in DB to exclude.")""" new_code = """ # 1. Get emails that have ALREADY purchased anything (in THIS specific job) purchased_emails = set() if exclude_purchased_emails: from sqlalchemy import or_ # We look ONLY within the CURRENT job to find siblings that were already purchased purchased_results = db.query(JobParticipant.email_eltern).filter( JobParticipant.job_id == job_id, or_(JobParticipant.has_orders == 1, JobParticipant.digital_package_ordered == 1), JobParticipant.email_eltern != "", JobParticipant.email_eltern != None ).all() purchased_emails = {r[0].lower() for r in purchased_results} logger.info(f"Task {task_id}: Found {len(purchased_emails)} unique emails with existing purchases in THIS job to exclude.")""" if old_code in content: content = content.replace(old_code, new_code) with open('fotograf-de-scraper/backend/main.py', 'w') as f: f.write(content) print("Filter logic patched successfully") else: print("Old code not found")