akef 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
akef/models/extra.py ADDED
@@ -0,0 +1,207 @@
1
+ from __future__ import annotations
2
+
3
+ import html
4
+ import re
5
+
6
+ from pydantic import Field
7
+
8
+ from akef.models.base import Model, Timestamp
9
+
10
+
11
+ class Notice(Model):
12
+ id: str = Field("", alias="cid")
13
+ tab: str = ""
14
+ title: str = ""
15
+ header: str = ""
16
+ start_at: Timestamp = None
17
+ data: dict = {}
18
+
19
+ @property
20
+ def headline(self) -> str:
21
+ return self.header or " ".join(self.title.replace("\\n", "\n").split())
22
+
23
+ @property
24
+ def html(self) -> str:
25
+ return self.data.get("html") or ""
26
+
27
+ @property
28
+ def image(self) -> str:
29
+ if self.data.get("url"):
30
+ return self.data["url"]
31
+ found = re.search(r'<img[^>]+src="([^"]+)"', self.html)
32
+ return found.group(1) if found else ""
33
+
34
+ @property
35
+ def text(self) -> str:
36
+ body = re.sub(r"<br\s*/?>|</p>|</li>", "\n", self.html)
37
+ body = html.unescape(re.sub(r"<[^>]+>", "", body))
38
+ return re.sub(r"\n{3,}", "\n\n", body).strip()
39
+
40
+
41
+ class Owned(Model):
42
+ id: str
43
+ name: str = ""
44
+ count: int = 1
45
+
46
+
47
+ class Inventory(Model):
48
+ operators: list[Owned] = []
49
+ weapons: list[Owned] = []
50
+ gear: list[Owned] = []
51
+ tacticals: list[Owned] = []
52
+
53
+
54
+ class WikiItem(Model):
55
+ id: str = Field("", alias="itemId")
56
+ name: str = ""
57
+ brief: dict = {}
58
+ document: dict | None = None
59
+
60
+ @property
61
+ def cover(self) -> str:
62
+ return self.brief.get("cover") or ""
63
+
64
+ @property
65
+ def illustration(self) -> str:
66
+ return ((self.document or {}).get("extraInfo") or {}).get("illustration") or self.cover
67
+
68
+ @property
69
+ def description(self) -> str:
70
+ return _blocks(self.brief.get("description"))
71
+
72
+ def text(self, doc_id: str) -> str:
73
+ return _blocks(((self.document or {}).get("documentMap") or {}).get(doc_id))
74
+
75
+ def content(self, doc_id: str) -> list[WikiBlock]:
76
+ document = ((self.document or {}).get("documentMap") or {}).get(doc_id)
77
+ if not document:
78
+ return []
79
+ blocks = document.get("blockMap") or {}
80
+ return [b for block_id in document.get("blockIds") or [] for b in _content(blocks, block_id)]
81
+
82
+ @property
83
+ def info(self) -> list[tuple[str, str]]:
84
+ out = []
85
+ for widget in ((self.document or {}).get("widgetCommonMap") or {}).values():
86
+ out += [(row.get("label", ""), row.get("value", "")) for row in widget.get("tableList") or []]
87
+ return out
88
+
89
+ @property
90
+ def sections(self) -> list[WikiSection]:
91
+ doc = self.document or {}
92
+ widgets = doc.get("widgetCommonMap") or {}
93
+ out = []
94
+ for chapter in doc.get("chapterGroup") or []:
95
+ for ref in chapter.get("widgets") or []:
96
+ widget = widgets.get(ref.get("id")) or {}
97
+ icons = {tab.get("tabId"): tab.get("icon", "") for tab in widget.get("tabList") or []}
98
+ entries = []
99
+ for tab_id, tab in (widget.get("tabDataMap") or {}).items():
100
+ intro = tab.get("intro") or {}
101
+ entries.append(WikiEntry(
102
+ name=intro.get("name", ""),
103
+ kind=intro.get("type", ""),
104
+ icon=icons.get(tab_id, ""),
105
+ text=self.text(intro.get("description", "")) or self.text(tab.get("content", "")),
106
+ content=self.content(tab.get("content", "")),
107
+ ))
108
+ out.append(WikiSection(chapter=chapter.get("title", ""), title=ref.get("title", "").lstrip("/"),
109
+ entries=entries))
110
+ return out
111
+
112
+ @property
113
+ def game_id(self) -> str:
114
+ return ((self.brief.get("associate") or {}).get("id")) or ""
115
+
116
+
117
+ class WikiLink(Model):
118
+ id: str
119
+ count: int = 0
120
+
121
+
122
+ class WikiCell(Model):
123
+ text: str = ""
124
+ links: list[WikiLink] = []
125
+ images: list[str] = []
126
+
127
+
128
+ class WikiBlock(Model):
129
+ kind: str
130
+ text: str = ""
131
+ bold: bool = False
132
+ image: str = ""
133
+ rows: list[list[WikiCell]] = []
134
+
135
+
136
+ class WikiEntry(Model):
137
+ name: str = ""
138
+ kind: str = ""
139
+ icon: str = ""
140
+ text: str = ""
141
+ content: list[WikiBlock] = []
142
+
143
+
144
+ class WikiSection(Model):
145
+ chapter: str = ""
146
+ title: str = ""
147
+ entries: list[WikiEntry] = []
148
+
149
+
150
+ def _blocks(document) -> str:
151
+ if not document:
152
+ return ""
153
+ blocks = document.get("blockMap") or {}
154
+ lines = []
155
+
156
+ def walk(block_id):
157
+ block = blocks.get(block_id) or {}
158
+ runs = (block.get("text") or {}).get("inlineElements") or []
159
+ line = "".join((r.get("text") or {}).get("text", "") for r in runs).strip()
160
+ if line:
161
+ lines.append(line)
162
+ for child in block.get("childIds") or []:
163
+ walk(child)
164
+
165
+ for block_id in document.get("blockIds") or []:
166
+ walk(block_id)
167
+ return "\n".join(lines)
168
+
169
+
170
+ def _cell(blocks, ids) -> WikiCell:
171
+ texts, links, images = [], [], []
172
+ stack = list(ids)
173
+ while stack:
174
+ block = blocks.get(stack.pop(0)) or {}
175
+ if block.get("kind") == "image":
176
+ images.append((block.get("image") or {}).get("url", ""))
177
+ line = ""
178
+ for run in (block.get("text") or {}).get("inlineElements") or []:
179
+ if run.get("kind") == "entry":
180
+ entry = run.get("entry") or {}
181
+ links.append(WikiLink(id=str(entry.get("id", "")), count=int(entry.get("count") or 0)))
182
+ else:
183
+ line += (run.get("text") or {}).get("text", "")
184
+ if line.strip():
185
+ texts.append(line.strip())
186
+ stack = list(block.get("childIds") or []) + list(((block.get(block.get("kind") or "") or {}).get("childIds")) or []) + stack
187
+ return WikiCell(text="\n".join(texts), links=links, images=[i for i in images if i])
188
+
189
+
190
+ def _content(blocks, block_id) -> list[WikiBlock]:
191
+ block = blocks.get(block_id) or {}
192
+ kind = block.get("kind")
193
+ if kind == "text":
194
+ runs = (block.get("text") or {}).get("inlineElements") or []
195
+ text = "".join((r.get("text") or {}).get("text", "") for r in runs).strip()
196
+ return [WikiBlock(kind="text", text=text, bold=all(r.get("bold") for r in runs))] if text else []
197
+ if kind == "image":
198
+ return [WikiBlock(kind="image", image=(block.get("image") or {}).get("url", ""))]
199
+ if kind == "table":
200
+ table = block.get("table") or {}
201
+ cells = table.get("cellMap") or {}
202
+ rows = []
203
+ for row in table.get("rowIds") or []:
204
+ rows.append([_cell(blocks, (cells.get(f"{row}_{col}") or {}).get("childIds") or []) for col in table.get("columnIds") or []])
205
+ return [WikiBlock(kind="table", rows=rows)]
206
+ children = list(block.get("childIds") or []) + list(((block.get(kind or "") or {}).get("childIds")) or [])
207
+ return [b for child in children for b in _content(blocks, child)]
akef/models/game.py ADDED
@@ -0,0 +1,113 @@
1
+ from __future__ import annotations
2
+
3
+ from pydantic import AliasChoices, Field, RootModel
4
+
5
+ from akef.models.base import Model, Tag, Timestamp
6
+
7
+
8
+ class Reward(Model):
9
+ id: str
10
+ name: str = ""
11
+ count: int = 0
12
+ icon: str = ""
13
+
14
+ @property
15
+ def display_name(self) -> str:
16
+ # some names come as "Full Name|Short", keep the full one
17
+ return self.name.split("|")[0]
18
+
19
+
20
+ class Day(Model):
21
+ award_id: str
22
+ available: bool = False
23
+ done: bool = False
24
+
25
+
26
+ class Attendance(Model):
27
+ calendar: list[Day] = []
28
+ first: list[Day] = []
29
+ resource_info_map: dict[str, Reward] = {}
30
+ has_today: bool = False
31
+ current_ts: Timestamp = None
32
+
33
+ @property
34
+ def claimed(self) -> int:
35
+ return sum(1 for d in self.calendar if d.done)
36
+
37
+ @property
38
+ def today(self) -> Day | None:
39
+ return next((d for d in self.calendar if d.available and not d.done), None)
40
+
41
+ def reward(self, day: Day) -> Reward | None:
42
+ return self.resource_info_map.get(day.award_id)
43
+
44
+
45
+ class Award(Model):
46
+ id: str
47
+ type: int = 0
48
+
49
+
50
+ class CheckIn(Model):
51
+ award_ids: list[Award] = []
52
+ tomorrow_award_ids: list[Award] = []
53
+ resource_info_map: dict[str, Reward] = {}
54
+
55
+ @property
56
+ def rewards(self) -> list[Reward]:
57
+ return [self.resource_info_map[a.id] for a in self.award_ids if a.id in self.resource_info_map]
58
+
59
+ @property
60
+ def tomorrow(self) -> list[Reward]:
61
+ return [self.resource_info_map[a.id] for a in self.tomorrow_award_ids if a.id in self.resource_info_map]
62
+
63
+
64
+ class BannerItem(Model):
65
+ id: str
66
+ name: str = ""
67
+ pic: str = ""
68
+ rarity: str = ""
69
+ pc_link: str = ""
70
+ dot_type: str = ""
71
+
72
+ @property
73
+ def stars(self) -> int:
74
+ tail = self.rarity.rsplit("_", 1)[-1]
75
+ return int(tail) if tail.isdigit() else 0
76
+
77
+ @property
78
+ def featured(self) -> bool:
79
+ return self.dot_type == "label_type_up"
80
+
81
+
82
+ class Banner(Model):
83
+ id: str
84
+ name: str = ""
85
+ sort_id: int = 0
86
+ items: list[BannerItem] = Field([], validation_alias=AliasChoices("chars", "weapons", "items"))
87
+ start_at_ts: Timestamp = None
88
+ end_at_ts: Timestamp = None
89
+ pool_start_at_ts: Timestamp = None
90
+ pool_end_at_ts: Timestamp = None
91
+ europe_pool_start_at_ts: Timestamp = None
92
+ europe_pool_end_at_ts: Timestamp = None
93
+
94
+ def ends_at(self, server_type: str = "as"):
95
+ # eu servers close a bit earlier than the rest
96
+ if server_type == "eu" and self.europe_pool_end_at_ts:
97
+ return self.europe_pool_end_at_ts
98
+ return self.pool_end_at_ts or self.end_at_ts
99
+
100
+
101
+ class Enums(RootModel[dict[str, list[Tag]]]):
102
+ def __getitem__(self, group: str) -> list[Tag]:
103
+ return self.root.get(group, [])
104
+
105
+ def groups(self) -> list[str]:
106
+ return list(self.root)
107
+
108
+ def label(self, key: str) -> str | None:
109
+ for tags in self.root.values():
110
+ for tag in tags:
111
+ if tag.key == key:
112
+ return tag.value
113
+ return None
akef/models/pulls.py ADDED
@@ -0,0 +1,149 @@
1
+ from __future__ import annotations
2
+
3
+ import csv
4
+ import io
5
+ from datetime import datetime, timezone
6
+ from pathlib import Path
7
+ from typing import Annotated
8
+
9
+ from pydantic import AliasChoices, BeforeValidator, ConfigDict, Field
10
+
11
+ from akef.models.base import Model
12
+
13
+ OPERATOR_BANNERS = ("special", "standard", "rerun", "beginner", "joint")
14
+ # limited operator banners share one 80 pity, the 120 for the featured one is per banner
15
+ LIMITED = ("special", "rerun", "joint")
16
+
17
+
18
+ def _millis(value):
19
+ if isinstance(value, datetime) or value in (None, "", "0"):
20
+ return value or None
21
+ if isinstance(value, str) and not value.isdigit():
22
+ return value
23
+ return datetime.fromtimestamp(int(value) / 1000, tz=timezone.utc)
24
+
25
+
26
+ class Pull(Model):
27
+ model_config = ConfigDict(extra="ignore")
28
+
29
+ kind: str = "draw"
30
+ banner: str = ""
31
+ pool_id: str = ""
32
+ pool_name: str = ""
33
+ name: str = Field("", validation_alias=AliasChoices("charName", "weaponName", "nameText", "name"))
34
+ item_id: str = Field("", validation_alias=AliasChoices("charId", "weaponId", "itemId", "item_id"))
35
+ rarity: int = 0
36
+ is_free: bool = False
37
+ is_new: bool = False
38
+ pulled_at: Annotated[datetime | None, BeforeValidator(_millis)] = Field(
39
+ None, validation_alias=AliasChoices("gachaTs", "pulledAt", "pulled_at")
40
+ )
41
+ seq_id: int = 0
42
+
43
+
44
+ def since_last(pulls: list[Pull], rarity: int = 6) -> int:
45
+ count = 0
46
+ for pull in reversed(pulls):
47
+ if pull.rarity >= rarity:
48
+ break
49
+ # urgent recruitment pulls are free and don't move pity
50
+ if not pull.is_free:
51
+ count += 1
52
+ return count
53
+
54
+
55
+ class Pity(Model):
56
+ name: str
57
+ since_six: int
58
+ hard: int
59
+ banner: str = ""
60
+ banner_pulls: int = 0
61
+ featured_at: int = 0
62
+
63
+ @property
64
+ def left(self) -> int:
65
+ return max(0, self.hard - self.since_six)
66
+
67
+
68
+ CSV_FIELDS = ("uid", "group", "kind", "banner", "pool_id", "pool_name", "name", "item_id", "rarity", "is_free", "is_new",
69
+ "pulled_at", "seq_id")
70
+
71
+
72
+ class Pulls(Model):
73
+ uid: str = ""
74
+ operators: list[Pull] = []
75
+ weapons: list[Pull] = []
76
+ gifts: list[Pull] = []
77
+
78
+ def to_json(self, indent: int | None = 2) -> str:
79
+ return self.model_dump_json(indent=indent)
80
+
81
+ def to_csv(self) -> str:
82
+ out = io.StringIO()
83
+ writer = csv.DictWriter(out, CSV_FIELDS, lineterminator="\n")
84
+ writer.writeheader()
85
+ for group in ("operators", "weapons", "gifts"):
86
+ for pull in getattr(self, group):
87
+ row = pull.model_dump(include=set(CSV_FIELDS))
88
+ row["pulled_at"] = pull.pulled_at.isoformat() if pull.pulled_at else ""
89
+ row["is_free"], row["is_new"] = str(pull.is_free).lower(), str(pull.is_new).lower()
90
+ writer.writerow(dict(row, uid=self.uid, group=group))
91
+ return out.getvalue()
92
+
93
+ def save(self, path: str | Path) -> Path:
94
+ path = Path(path)
95
+ text = self.to_csv() if path.suffix.lower() == ".csv" else self.to_json()
96
+ path.write_text(text, encoding="utf-8", newline="")
97
+ return path
98
+
99
+ @classmethod
100
+ def load(cls, path: str | Path) -> Pulls:
101
+ path = Path(path)
102
+ text = path.read_text(encoding="utf-8")
103
+ if path.suffix.lower() != ".csv":
104
+ return cls.model_validate_json(text)
105
+ pulls = cls()
106
+ for row in csv.DictReader(io.StringIO(text)):
107
+ pulls.uid = row.pop("uid") or pulls.uid
108
+ getattr(pulls, row.pop("group")).append(Pull.model_validate(row))
109
+ return pulls
110
+
111
+ def banner(self, kind: str) -> list[Pull]:
112
+ return [p for p in self.operators if p.banner == kind]
113
+
114
+ def weapon_banner(self, pool_id: str) -> list[Pull]:
115
+ return [p for p in self.weapons if p.pool_id == pool_id]
116
+
117
+ @property
118
+ def weapon_pools(self) -> list[str]:
119
+ return list(dict.fromkeys(p.pool_id for p in self.weapons))
120
+
121
+ @property
122
+ def last_seq(self) -> dict[str, int]:
123
+ out: dict[str, int] = {}
124
+ for p in self.operators:
125
+ out[p.banner] = max(out.get(p.banner, 0), p.seq_id)
126
+ for p in self.weapons:
127
+ out[p.pool_id] = max(out.get(p.pool_id, 0), p.seq_id)
128
+ return out
129
+
130
+ def pity(self) -> list[Pity]:
131
+ out = []
132
+ limited = [p for p in self.operators if p.banner in LIMITED]
133
+ if limited:
134
+ current = limited[-1].pool_id
135
+ paid = [p for p in limited if p.pool_id == current and not p.is_free]
136
+ out.append(Pity(name="Limited operators", since_six=since_last(limited), hard=80,
137
+ banner=limited[-1].pool_name, banner_pulls=len(paid), featured_at=120))
138
+ standard = self.banner("standard")
139
+ if standard:
140
+ out.append(Pity(name="Standard", since_six=since_last(standard), hard=80, banner=standard[-1].pool_name,
141
+ banner_pulls=sum(not p.is_free for p in standard), featured_at=300))
142
+ beginner = self.banner("beginner")
143
+ if beginner and not any(p.rarity == 6 for p in beginner):
144
+ out.append(Pity(name="Beginner", since_six=since_last(beginner), hard=50))
145
+ for pool in reversed(self.weapon_pools):
146
+ pulls = self.weapon_banner(pool)
147
+ out.append(Pity(name="Weapons", since_six=since_last(pulls), hard=40, banner=pulls[-1].pool_name,
148
+ banner_pulls=sum(not p.is_free for p in pulls), featured_at=80))
149
+ return out
akef/py.typed ADDED
File without changes
akef/signing.py ADDED
@@ -0,0 +1,20 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import hmac
5
+ import json
6
+ import time
7
+
8
+ from akef.constants import PLATFORM, VNAME
9
+
10
+
11
+ def base_headers(ts: str) -> dict[str, str]:
12
+ # key order matters, the server hashes this exact json
13
+ return {"platform": PLATFORM, "timestamp": ts, "dId": "", "vName": VNAME}
14
+
15
+
16
+ def sign(path: str, body: str, salt: str, ts: str | None = None) -> dict[str, str]:
17
+ ts = ts or str(int(time.time()))
18
+ head = json.dumps(base_headers(ts), separators=(",", ":"))
19
+ digest = hmac.new(salt.encode(), f"{path}{body}{ts}{head}".encode(), hashlib.sha256).hexdigest()
20
+ return {**base_headers(ts), "sign": hashlib.md5(digest.encode()).hexdigest()}
akef/wiki.py ADDED
@@ -0,0 +1,193 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from enum import Enum
5
+
6
+ # spaces, separators and zero-width spaces the wiki leaves in otherwise empty cells
7
+ BLANK = " ·​"
8
+
9
+
10
+ @dataclass
11
+ class WikiSkill:
12
+ name: str
13
+ kind: str
14
+ icon: str
15
+ text: str
16
+
17
+
18
+ @dataclass
19
+ class Cost:
20
+ name: str
21
+ icon: str
22
+ count: int
23
+
24
+
25
+ @dataclass
26
+ class Tier:
27
+ name: str
28
+ effect: str
29
+ requirement: str
30
+ costs: list[Cost] = field(default_factory=list)
31
+
32
+
33
+ @dataclass
34
+ class Node:
35
+ name: str
36
+ kind: str
37
+ icon: str
38
+ tiers: list[Tier] = field(default_factory=list)
39
+
40
+
41
+ @dataclass
42
+ class Potential:
43
+ name: str
44
+ icon: str
45
+ text: str
46
+
47
+
48
+ @dataclass
49
+ class Intel:
50
+ label: str
51
+ title: str
52
+ text: str
53
+
54
+
55
+ @dataclass
56
+ class Story:
57
+ title: str
58
+ unlock: str
59
+ text: str
60
+
61
+
62
+ class WikiPart(str, Enum):
63
+ OVERVIEW = "overview"
64
+ SKILLS = "skills"
65
+ TALENTS = "talents"
66
+ GROWTH = "growth"
67
+ PROFILE = "profile"
68
+ LORE = "lore"
69
+
70
+ @property
71
+ def needs_index(self) -> bool:
72
+ return self in (WikiPart.TALENTS, WikiPart.GROWTH, WikiPart.PROFILE)
73
+
74
+
75
+ @dataclass
76
+ class WikiPage:
77
+ name: str
78
+ art: str
79
+ quote: str
80
+ bio: str
81
+ info: list[tuple[str, str]] = field(default_factory=list)
82
+ skills: list[WikiSkill] = field(default_factory=list)
83
+ talents: list[Node] = field(default_factory=list)
84
+ promotions: list[Node] = field(default_factory=list)
85
+ potentials: list[Potential] = field(default_factory=list)
86
+ weapons: list[tuple[str, list[Cost]]] = field(default_factory=list)
87
+ intel: list[Intel] = field(default_factory=list)
88
+ stories: list[Story] = field(default_factory=list)
89
+
90
+ @property
91
+ def parts(self) -> list[WikiPart]:
92
+ has = {
93
+ WikiPart.TALENTS: self.talents,
94
+ WikiPart.GROWTH: self.promotions or self.potentials,
95
+ WikiPart.LORE: self.stories,
96
+ }
97
+ return [part for part in WikiPart if has.get(part, True)]
98
+
99
+ def urls(self) -> list[str]:
100
+ out = [self.art] + [s.icon for s in self.skills] + [p.icon for p in self.potentials]
101
+ for node in self.talents + self.promotions:
102
+ out.append(node.icon)
103
+ out += [c.icon for tier in node.tiers for c in tier.costs]
104
+ out += [c.icon for _, costs in self.weapons for c in costs]
105
+ return [u for u in out if u]
106
+
107
+
108
+ def _costs(cell, index) -> list[Cost]:
109
+ out = []
110
+ for link in cell.links:
111
+ target = index.get(link.id)
112
+ if target is not None:
113
+ out.append(Cost(target.name, target.cover, link.count))
114
+ return out
115
+
116
+
117
+ def _tables(entry):
118
+ return [block for block in entry.content if block.kind == "table"]
119
+
120
+
121
+ def _node(entry, index) -> Node:
122
+ titles = [block.text for block in entry.content if block.kind == "text"]
123
+ tiers = []
124
+ for table in _tables(entry):
125
+ for row in table.rows:
126
+ # header rows start with an empty cell, explanation rows have no cost column
127
+ if len(row) < 3 or not row[0].text or (not row[-1].links and row[-1].text == "Cost"):
128
+ continue
129
+ middle = [text for text in (cell.text.strip(BLANK) for cell in row[2:-1]) if text]
130
+ tiers.append(Tier(row[0].text, row[1].text, " · ".join(middle), _costs(row[-1], index)))
131
+ return Node(titles[0] if titles else "", titles[1] if len(titles) > 1 else "", entry.icon, tiers)
132
+
133
+
134
+ def wiki_page(item, index: dict | None = None) -> WikiPage:
135
+ index = index or {}
136
+ lines = [line for line in item.description.splitlines() if line.strip()]
137
+ quote = lines[0].strip('"“” ') if lines and lines[0].startswith(('"', "“")) else ""
138
+ page = WikiPage(
139
+ name=item.name,
140
+ art=item.illustration,
141
+ quote=quote,
142
+ bio=" ".join(lines[1:] if quote else lines),
143
+ info=[(k, v) for k, v in item.info if k and v and "CV" not in k and v != item.name],
144
+ )
145
+ kinds = set()
146
+ for section in item.sections:
147
+ if section.title == "Combat Skills":
148
+ for entry in section.entries:
149
+ if entry.kind not in kinds:
150
+ kinds.add(entry.kind)
151
+ page.skills.append(WikiSkill(entry.name.split(" (")[0], entry.kind, entry.icon, entry.text))
152
+ elif section.title == "Talent Nodes":
153
+ page.talents = [_node(entry, index) for entry in section.entries]
154
+ elif section.title == "Elite":
155
+ page.promotions = [_node(entry, index) for entry in section.entries]
156
+ elif section.title == "Potential Phases":
157
+ for entry in section.entries:
158
+ for table in _tables(entry):
159
+ for row in table.rows:
160
+ if len(row) >= 3 and "POTENTIAL" in row[1].text:
161
+ name = row[1].text.split("\n")[0]
162
+ icon = row[0].images[0] if row[0].images else ""
163
+ page.potentials.append(Potential(name, icon, row[2].text))
164
+ elif section.title == "Game Recommendation":
165
+ for entry in section.entries:
166
+ for table in _tables(entry):
167
+ if len(table.rows) >= 2:
168
+ for head, cell in zip(table.rows[0], table.rows[1]):
169
+ page.weapons.append((head.text, _costs(cell, index)))
170
+ elif section.title == "Profile":
171
+ for entry in section.entries:
172
+ texts = [b for b in entry.content if b.kind == "text"]
173
+ if len(texts) < 2:
174
+ continue
175
+ unlock = texts[1].text if texts[1].bold and texts[1].text.startswith("Reach") else ""
176
+ body = texts[2:] if unlock else texts[1:]
177
+ page.stories.append(Story(texts[0].text.title(), unlock, "\n".join(b.text for b in body)))
178
+ elif section.title == "Operator Intel":
179
+ for entry in section.entries:
180
+ texts = [b for b in entry.content if b.kind == "text"]
181
+ i = 0
182
+ while i < len(texts):
183
+ label = texts[i].text
184
+ if i + 1 < len(texts) and texts[i + 1].bold:
185
+ body = texts[i + 2].text if i + 2 < len(texts) else ""
186
+ page.intel.append(Intel(label.split(":")[0], texts[i + 1].text, body))
187
+ i += 3
188
+ elif i + 1 < len(texts):
189
+ page.intel.append(Intel(label, texts[i + 1].text, ""))
190
+ i += 2
191
+ else:
192
+ i += 1
193
+ return page