11from datetime import datetime
22from os import environ
3- from typing import Final
3+ from typing import Annotated , Final
44
55import httpx
66from httpx import Response
77from pydantic .networks import HttpUrl
8+ from pydantic .types import FilePath
89from 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
1315BLOG_URL = "https://it176131.github.io"
1416NSMAP : Final [dict [str , str ]] = {"" : "http://www.w3.org/2005/Atom" }
17+ app = Typer ()
1518
1619
1720class 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