Skip to content

Commit

Permalink
Inline questions
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
shenanigansd authored Oct 25, 2024
1 parent 3806227 commit 8ca2162
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 48 deletions.
28 changes: 10 additions & 18 deletions src/crazylibs/stories.py
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:

Check failure on line 8 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (I001)

src/crazylibs/stories.py:3:1: I001 Import block is un-sorted or un-formatted
"""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] = {}

Check failure on line 17 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (F841)

src/crazylibs/stories.py:17:5: F841 Local variable `context` is assigned to but never used

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))

Check failure on line 21 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (T201)

src/crazylibs/stories.py:21:9: T201 `print` found
print("new contexts", re.findall(r"\([a-zA-Z]+ : \d+\)", line))

Check failure on line 22 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (T201)

src/crazylibs/stories.py:22:9: T201 `print` found
print("existing", re.findall(r"\(\d+\)", line))

Check failure on line 23 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (T201)

src/crazylibs/stories.py:23:9: T201 `print` found

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)

Check failure on line 30 in src/crazylibs/stories.py

View workflow job for this annotation

GitHub Actions / lint / lint

Ruff (ERA001)

src/crazylibs/stories.py:30:5: ERA001 Found commented-out code
39 changes: 9 additions & 30 deletions stories/a_day_at_the_zoo.txt
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!

0 comments on commit 8ca2162

Please sign in to comment.