#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Sep 11 14:23:48 2025 @author: sma """ import re def parse_log_file(log_content: str): """ Parses a CS 1.6 log file and extracts admin actions and chat messages. Returns a dictionary with admin names as keys. """ log_lines = log_content.splitlines() admin_actions = {} # Regex patterns for admin actions action_patterns = { "kicked": r'"([^<]+)<\d+>]+><[^>]*>" kick', "banned": r'"([^<]+)<\d+>]+><[^>]*>" banned', "slapped": r'"([^<]+)<\d+>]+><[^>]*>" slap with', "slayed": r'"([^<]+)<\d+>]+><[^>]*>" slay', "transfers": r'"([^<]+)<\d+>]+><[^>]*>" transfer', "renamed" : r'\[crx_nonamechange\.amxx\]\s+(.*?)\s+changed', } # Regex for admin chat admin_chat_pattern = r'\[adminchat\.amxx\] Chat: "([^"]+)<\d+><[^>]+><>" tsay "(.*)"' for line in log_lines: found = False for action, pattern in action_patterns.items(): match = re.search(pattern, line) if match: admin = match.group(1).strip() if admin not in admin_actions: admin_actions[admin] = {a: 0 for a in list(action_patterns.keys()) + ["whitechat"]} admin_actions[admin][action] += 1 found = True break if not found: chat_match = re.search(admin_chat_pattern, line) if chat_match: admin = chat_match.group(1).strip() message = chat_match.group(2).strip() if admin not in admin_actions: admin_actions[admin] = {a: 0 for a in list(action_patterns.keys()) + ["whitechat"]} if "message" not in admin_actions[admin]: admin_actions[admin]["message"] = [] admin_actions[admin]["whitechat"] += 1 admin_actions[admin]["message"].append(message) return admin_actions # ---------------- TEST MAIN -------------------------------------------------- if __name__ == "__main__": from pathlib import Path import pprint # Pfad zur Logdatei anpassen log_path = Path("L20250908.log") if log_path.exists(): with log_path.open("r", encoding="utf-8", errors="ignore") as f: log_content = f.read() result = parse_log_file(log_content) pprint.pprint(result) else: print(f"File not found: {log_path}")