Spaces:
Sleeping
Sleeping
Download src/parser/parsing.py from DSGC/admin_dashboard: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/spaces/DSGC/admin_dashboard/resolve/main/src/parser/parsing.py
- Command line
-
hf download hf://spaces/DSGC/admin_dashboard/src/parser/parsing.py
-
curl -L -o parsing.py https://huggingface.co/spaces/DSGC/admin_dashboard/resolve/main/src/parser/parsing.py
2.54 kB
| #!/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+><STEAM_[^>]+><[^>]*>" kick', | |
| "banned": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" banned', | |
| "slapped": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" slap with', | |
| "slayed": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" slay', | |
| "transfers": r'"([^<]+)<\d+><STEAM_[^>]+><[^>]*>" 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}") | |