from pathlib import Path
import sys

html_path = Path(sys.argv[1])
html = html_path.read_text(encoding='utf-8')
html = html.replace('249389-secure-dm-android-foundation', '249390b-friend-identity-acceptance')
script = '<script src="/js/friend_identity_v249390.js?v=249390b-friend-identity-acceptance" charset="utf-8" defer></script>'
if 'friend_identity_v249390.js' not in html:
    marker = '<script src="/js/secure_messaging_v249389.js?v=249390b-friend-identity-acceptance" charset="utf-8" defer></script>'
    if marker in html:
        html = html.replace(marker, marker + '\n' + script)
    else:
        html = html.replace('</body>', script + '\n</body>')
html_path.write_text(html, encoding='utf-8')
