feat: add all_files iterator to simplify searching
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
1ce0790c0c
commit
ee91b2e8db
3 changed files with 62 additions and 23 deletions
|
|
@ -1,14 +1,16 @@
|
|||
import glob
|
||||
import os
|
||||
import typer
|
||||
from datetime import datetime
|
||||
from shutil import move
|
||||
from typing import Generator
|
||||
|
||||
import click
|
||||
import typer
|
||||
from rich import print
|
||||
from rich.markdown import Markdown
|
||||
from rich.panel import Panel
|
||||
from shutil import move
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from streamer.parse.attach_markdown import StreamFileWithMarkdown, attach_markdown
|
||||
from streamer.parse.parse import parse_markdown_file
|
||||
from streamer.query.task import find_by_markers
|
||||
from streamer.settings import Settings
|
||||
|
|
@ -16,28 +18,28 @@ from streamer.settings import Settings
|
|||
app = typer.Typer()
|
||||
|
||||
|
||||
@app.command()
|
||||
def todo() -> None:
|
||||
def all_files() -> Generator[StreamFileWithMarkdown]:
|
||||
for file_name in glob.glob(f"{glob.escape(Settings().base_folder)}/*.md"):
|
||||
with open(file_name, "r") as file:
|
||||
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"])
|
||||
yield attach_markdown(
|
||||
parse_markdown_file(file_name, file_content), file_content
|
||||
)
|
||||
|
||||
for task_shard in open_tasks:
|
||||
print(
|
||||
Panel(
|
||||
Markdown(
|
||||
"\n".join(
|
||||
file_content.splitlines()[
|
||||
task_shard.start_line - 1 : task_shard.end_line
|
||||
]
|
||||
)
|
||||
),
|
||||
title=f"{file_name}:{task_shard.start_line}",
|
||||
)
|
||||
|
||||
@app.command()
|
||||
def todo() -> None:
|
||||
for sharded_document in all_files():
|
||||
if sharded_document.shard:
|
||||
open_tasks = find_by_markers(sharded_document.shard, ["Task"], ["Done"])
|
||||
|
||||
for task_shard in open_tasks:
|
||||
print(
|
||||
Panel(
|
||||
Markdown(task_shard.markdown_content),
|
||||
title=f"{sharded_document.filename}:{task_shard.start_line}",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@app.command()
|
||||
|
|
@ -59,7 +61,9 @@ def new() -> None:
|
|||
parsed_content = parse_markdown_file(prelimary_path, content)
|
||||
|
||||
final_file_name = f"{timestamp}.md"
|
||||
if parsed_content.shard is not None and len(markers := parsed_content.shard.markers):
|
||||
if parsed_content.shard is not None and len(
|
||||
markers := parsed_content.shard.markers
|
||||
):
|
||||
final_file_name = f"{timestamp} {' '.join(markers)}.md"
|
||||
|
||||
final_path = os.path.join(streamer_directory, final_file_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue