1 from itertools import takewhile, dropwhile
2 from typing import Optional, Any
4 from mwparserfromhell.nodes import Template, Text, Tag
5 from mwparserfromhell.wikicode import Wikicode
8 def optional_set(haystack: dict, key: str, value: Optional[Any]):
9 """Sets the key to value in haystack only if value is not None"""
14 def get_sledrun_description(sledrun: Wikicode) -> Optional[str]:
15 """Get description from sledrun"""
16 for v in sledrun.get_sections(levels=[2], matches='Allgemeines', include_headings=False):
17 dw = dropwhile(lambda n: isinstance(n, Template) or (isinstance(n, Text) and not str(n).strip()), v.nodes)
18 tw = takewhile(lambda n: not (isinstance(n, Tag) and str(n) == '*'), dw)
19 result = str(Wikicode(tw)).strip()