-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: GitHub <[email protected]>
- Loading branch information
1 parent
3806227
commit 8ca2162
Showing
2 changed files
with
19 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,30 @@ | ||
"""Story functions.""" | ||
|
||
from pathlib import Path | ||
|
||
import re | ||
import typer | ||
|
||
|
||
def run_story(story_file: Path) -> None: | ||
"""Run a story.""" | ||
story_text = Path(story_file).read_text() | ||
raw_title, questions_block, template = story_text.split("---") | ||
|
||
title = raw_title.strip() | ||
|
||
question_rows = questions_block.strip().split("\n") | ||
questions = {} | ||
for row in question_rows: | ||
index, question = row.split(":") | ||
questions[index] = question.strip() | ||
raw_text = Path(story_file).read_text().strip() | ||
title, story_text = raw_text.split("\n", maxsplit=1) | ||
|
||
typer.echo(f'Welcome to "{title}"') | ||
typer.echo("") | ||
typer.echo("Please fill in the following words:") | ||
|
||
context = {} | ||
for index, question in questions.items(): | ||
context[index] = typer.prompt(question) | ||
context: dict[str, str] = {} | ||
|
||
text = template | ||
for index, item in context.items(): | ||
text = text.replace(f"({index})", item) | ||
lines = story_text.split("\n") | ||
for line in lines: | ||
print("oneoffs", re.findall(r"\([a-zA-Z]+\)", line)) | ||
print("new contexts", re.findall(r"\([a-zA-Z]+ : \d+\)", line)) | ||
print("existing", re.findall(r"\(\d+\)", line)) | ||
|
||
typer.echo("") | ||
typer.echo("Wow, what a good selection of words!") | ||
typer.echo("Here is your story:") | ||
typer.echo("") | ||
|
||
typer.echo(text) | ||
# typer.echo(story_text) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,12 @@ | ||
A Day at the Zoo | ||
--- | ||
1: adjective | ||
2: animal | ||
3: verb ending in -ing | ||
4: place | ||
5: adjective | ||
6: animal | ||
7: verb ending in -ing | ||
8: adjective | ||
9: food | ||
10: adjective | ||
11: animal | ||
12: adjective | ||
13: animal | ||
14: verb ending in -ing | ||
15: verb ending in -ing | ||
16: adjective | ||
17: adjective | ||
18: noun | ||
19: adjective | ||
--- | ||
One day, my friend and I decided to visit the zoo. We were very (1) to see all the animals. | ||
First, we saw the (2), which was (3) in its (4). | ||
Next, we went to the (5) exhibit where we saw a (6) that was (7). It was so (8)! | ||
One day, my friend and I decided to visit the zoo. We were very (adjective) to see all the animals. | ||
First, we saw the (animal), which was (verb ending in -ing) in its (place). | ||
Next, we went to the (adjective) exhibit where we saw a (animal) that was (verb ending in -ing). It was so (adjective)! | ||
|
||
After that, we decided to have some (9) for lunch. | ||
While eating, we saw a (10) (11) that tried to steal our (9)! | ||
We laughed and decided to go see the (12) (13) show. The (13) did tricks like (14) and (15). | ||
It was the most (16) part of our day. | ||
After that, we decided to have some (food : 9) for lunch. | ||
While eating, we saw a (adjective) (animal) that tried to steal our (9)! | ||
We laughed and decided to go see the (adjective) (animal) show. The (animal) did tricks like (verb ending in -ing) and (verb ending in -ing). | ||
It was the most (adjective) part of our day. | ||
|
||
Finally, we visited the gift shop and bought a (17) (18) as a souvenir. | ||
It was a (19) day at the zoo, and we couldn't wait to come back again! | ||
Finally, we visited the gift shop and bought a (adjective) (noun) as a souvenir. | ||
It was a (adjective) day at the zoo, and we couldn't wait to come back again! |