from pathlib import Path
p=Path('/opt/struktur/social-media-agent/app.py')
s=p.read_text()
old=''' if sort == "facebook":
platform_clause = (
"AND COALESCE(mas_relevant,0)=1 AND (COALESCE(platform_facebook,1)>=2 "
"OR lower(COALESCE(briefing_fb_fit,'')) IN ('ja','pruefen') "
"OR " + platform_expr + " IN ('facebook','meta','meta_ad') "
"OR source_type IN ('facebook_public','meta_ad'))"
)
'''
new=''' if sort == "facebook":
# Facebook ist Zielplattform: Quellplattform/Quelltyp sind kein Fit.
platform_clause = (
"AND COALESCE(mas_relevant,0)=1 AND "
"(COALESCE(platform_facebook,1)>=2 "
"OR lower(COALESCE(briefing_fb_fit,'')) IN ('ja','pruefen'))"
)
'''
assert old in s
p.write_text(s.replace(old,new,1))