From 5ead3c02a8b34553d77289db168775b1b1fc377e Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 25 Apr 2020 20:58:28 -0700 Subject: [PATCH] Add get_draft --- amanuensis/lexicon/__init__.py | 2 ++ amanuensis/lexicon/gameloop.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/amanuensis/lexicon/__init__.py b/amanuensis/lexicon/__init__.py index 4757828..949cb97 100644 --- a/amanuensis/lexicon/__init__.py +++ b/amanuensis/lexicon/__init__.py @@ -5,6 +5,7 @@ from .admin import ( from .gameloop import ( get_player_characters, get_player_drafts, + get_draft, attempt_publish) from .setup import ( player_can_join_lexicon, @@ -17,6 +18,7 @@ __all__ = [member.__name__ for member in [ load_all_lexicons, get_player_characters, get_player_drafts, + get_draft, attempt_publish, player_can_join_lexicon, add_player_to_lexicon, diff --git a/amanuensis/lexicon/gameloop.py b/amanuensis/lexicon/gameloop.py index ea854dc..49c45b5 100644 --- a/amanuensis/lexicon/gameloop.py +++ b/amanuensis/lexicon/gameloop.py @@ -2,7 +2,7 @@ Submodule of functions for managing lexicon games during the core game loop of writing and publishing articles. """ -from typing import Iterable, Any, List +from typing import Iterable, Any, List, Optional from amanuensis.config import ReadOnlyOrderedDict from amanuensis.models import LexiconModel @@ -45,6 +45,21 @@ def get_player_drafts( return drafts +def get_draft(lexicon: LexiconModel, aid: str) -> Optional[ReadOnlyOrderedDict]: + """ + Loads an article from its id + """ + article_fn = None + for filename in lexicon.ctx.draft.ls(): + if filename.endswith(f'{aid}.json'): + article_fn = filename + break + if not article_fn: + return None + with lexicon.ctx.draft.read(article_fn) as article: + return article + + def attempt_publish(lexicon: LexiconModel) -> None: """ If the lexicon's publsh policy allows the current set of approved