adding restock command

This commit is contained in:
evilchili
2023-05-13 13:24:43 -07:00
parent e0cb01ba2c
commit a6c101b01b
3 changed files with 45 additions and 4 deletions
+40 -1
View File
@@ -17,6 +17,7 @@ from pelican import main as pelican_main
from time import sleep
from site_tools.content_manager import create
from rolltable.tables import RollTable
CONFIG = {
@@ -103,7 +104,7 @@ def watch() -> None:
print(f"Watching {import_path}. CTRL+C to exit.")
while True:
watcher.examine()
sleep(1)
sleep(5)
@app.command()
@@ -158,6 +159,44 @@ def publish() -> None:
))
@app.command()
def restock(source: str = typer.Argument(
...,
help='The source file for the store.'
),
frequency: str = typer.Option(
'default',
help='use the specified frequency from the source file'),
die: int = typer.Option(
20,
help='The size of the die for which to create a table'),
template_dir: str = typer.Argument(
CONFIG['templates_path'],
help="Override the default location for markdown templates.",
)
) -> None:
rt = RollTable(
[Path(source).read_text()],
frequency=frequency,
die=die,
hide_rolls=True
)
store = rt.datasources[0].metadata['store']
click.edit(filename=create(
content_type='post',
title=store['title'],
template_dir=template_dir,
category='stores',
template='store',
extra_context=dict(
inventory=rt.as_markdown,
**store
)
))
@app.command()
def new(
content_type: ContentType = typer.Argument(
+4 -2
View File
@@ -7,7 +7,8 @@ from site_tools import SETTINGS
def create(content_type: str, title: str, template_dir: str,
category: str = None, template: str = None) -> str:
category: str = None, source: str = None, template: str = None,
extra_context: dict = {}) -> str:
"""
Return the path to a new source file.
"""
@@ -41,6 +42,7 @@ def create(content_type: str, title: str, template_dir: str,
'title': title,
'tags': content_type,
'date': datetime.datetime.now(),
'filename': str(relpath / target_filename)
'filename': str(relpath / target_filename),
**extra_context
})
return dest