Skip to content

Commit e351bfa

Browse files
committed
modified: .github/actions/recent-posts/main.py
- Converted script to typer app and added logic to append to README.md.
1 parent 050541d commit e351bfa

File tree

1 file changed

+20
-4
lines changed
  • .github/actions/recent-posts

1 file changed

+20
-4
lines changed

.github/actions/recent-posts/main.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from datetime import datetime
22
from os import environ
3-
from typing import Final
3+
from typing import Annotated, Final
44

55
import httpx
66
from httpx import Response
77
from pydantic.networks import HttpUrl
8+
from pydantic.types import FilePath
89
from pydantic_xml.model import (
910
attr, BaseXmlModel, computed_element, element, wrapped
1011
)
11-
from rich.console import Console
12+
from typer import Typer
13+
from typer.params import Argument
1214

1315
BLOG_URL = "https://it176131.github.io"
1416
NSMAP: Final[dict[str, str]] = {"": "http://www.w3.org/2005/Atom"}
17+
app = Typer()
1518

1619

1720
class Entry(BaseXmlModel, tag="entry", nsmap=NSMAP, search_mode="ordered"):
@@ -37,11 +40,24 @@ class Feed(BaseXmlModel, tag="feed", nsmap=NSMAP, search_mode="ordered"):
3740
entry: Entry
3841

3942

40-
if __name__ == "__main__":
43+
@app.command()
44+
def main(
45+
readme: Annotated[
46+
FilePath,
47+
Argument(help="Path to file where metadata will be written.")
48+
] = "README.md"
49+
) -> None:
50+
"""Write most recent blog post metadata to ``readme``."""
4151
resp: Response = httpx.get(url=f"{BLOG_URL}/feed.xml")
4252
xml: bytes = resp.content
43-
console = Console()
4453
model = Feed.from_xml(source=xml)
4554
json_string = model.model_dump_json()
4655
with open(environ["GITHUB_OUTPUT"], mode="a") as f:
4756
f.write(f"result={json_string}")
57+
58+
with readme.open(mode="a") as f:
59+
f.write(f"result={json_string}\n")
60+
61+
62+
if __name__ == "__main__":
63+
app()

0 commit comments

Comments
 (0)