feat: add smart parse engine to streamer entry point
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
8f5a000c5c
commit
e826101a24
1 changed files with 30 additions and 5 deletions
|
|
@ -1,15 +1,40 @@
|
|||
import glob
|
||||
import os
|
||||
|
||||
from streamer.parse import Shard
|
||||
from streamer.parse.parse import parse_markdown_file
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
|
||||
def find_by_markers(shard: Shard, has: list[str], has_not: list[str]) -> list[Shard]:
|
||||
found_shards = []
|
||||
|
||||
if any(tag in has for tag in shard.markers) and not any(
|
||||
tag in has_not for tag in shard.markers
|
||||
):
|
||||
found_shards.append(shard)
|
||||
|
||||
for child in shard.children:
|
||||
found_shards.extend(find_by_markers(child, has, has_not))
|
||||
|
||||
return found_shards
|
||||
|
||||
|
||||
def run() -> None:
|
||||
for file_name in glob.glob(f"{glob.escape(cwd)}/*.md"):
|
||||
with open(file_name, "r") as file:
|
||||
file_content: str = file.read()
|
||||
file_content = file.read()
|
||||
sharded_document = parse_markdown_file(file_name, file_content)
|
||||
if sharded_document.shard:
|
||||
open_tasks = find_by_markers(sharded_document.shard, ["Task"], ["Done"])
|
||||
|
||||
for line_number, line in enumerate(file_content.split("\n"), 1):
|
||||
if "@Task" in line and "@Done" not in line:
|
||||
print(line)
|
||||
print(f" {file_name}:{line_number}")
|
||||
for task_shard in open_tasks:
|
||||
print(
|
||||
"\n".join(
|
||||
file_content.splitlines()[
|
||||
task_shard.start_line - 1 : task_shard.end_line
|
||||
]
|
||||
)
|
||||
)
|
||||
print(f" {file_name}:{task_shard.start_line}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue