forked from xanadinn/DurisMUD
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparse_help_index.py
More file actions
executable file
·64 lines (49 loc) · 1.77 KB
/
parse_help_index.py
File metadata and controls
executable file
·64 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Parse help_index file and import all help topics into the database.
Format: Each entry starts with # on its own line, followed by "TITLE" line, then content
"""
import re
import sys
def parse_help_index(filename):
"""Parse help_index file into individual help entries."""
with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
# Split by # on its own line
entries = content.split('\n#\n')
help_entries = []
for entry in entries:
entry = entry.strip()
if not entry or entry.startswith('last update:'):
continue
lines = entry.split('\n')
if not lines:
continue
# First line should be the title in quotes
title_line = lines[0].strip()
# Extract title from quotes
match = re.match(r'^"([^"]+)"', title_line)
if not match:
continue
title = match.group(1).strip()
# Rest is content
content_lines = lines[1:]
content = '\n'.join(content_lines).strip()
# Remove the === lines at start/end
content = re.sub(r'^=+\n', '', content)
content = re.sub(r'\n=+$', '', content)
content = content.strip()
if title and content:
help_entries.append((title, content))
return help_entries
if __name__ == '__main__':
entries = parse_help_index('lib/information/help_index')
print(f"Parsed {len(entries)} help entries")
print("\nFirst 5 titles:")
for i, (title, content) in enumerate(entries[:5]):
print(f" {i+1}. '{title}' ({len(content)} bytes)")
# Look for human
for title, content in entries:
if 'human' in title.lower():
print(f"\nFound: '{title}'")
print(content[:200])