with open('proxy_server.py', 'r', encoding='utf-8') as f:
    content = f.read()

target = "if parsed.path == '/api/midas-trade':"
inject = """if parsed.path == '/api/midas-login':
            try:
                import subprocess
                import sys
                bot_path = os.path.join(BASE_DIR, 'midas_bot.py')
                if sys.platform == 'win32':
                    subprocess.Popen(['python', bot_path, '--login'], creationflags=subprocess.CREATE_NEW_CONSOLE)
                else:
                    subprocess.Popen(['python', bot_path, '--login'])
                self._send_json(200, {'success': True, 'message': 'Midas giris penceresi baslatildi'})
            except Exception as e:
                self._send_json(500, {'error': str(e)})
            return

        """ + target

if target in content:
    content = content.replace(target, inject)
    with open('proxy_server.py', 'w', encoding='utf-8') as f:
        f.write(content)
    print('PROXY LOGIN ENDPOINT EKLENDI!')
else:
    print('HEDEF BULUNAMADI!')
