Skip to content

Commit 2c8ce53

Browse files
committed
modified: .github/actions/recent-posts/main.py
- Added logic to add table with blog post as rich.Table. modified: .github/workflows/recent-posts.yml - Removed git diff. modified: README.md - Added comment lines so main.py knows where to add blog post table. # Conflicts: # README.md
1 parent fab493a commit 2c8ce53

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from os import environ
3+
import re
34
import subprocess
45
from typing import Annotated, Final
56

@@ -10,6 +11,7 @@
1011
from pydantic_xml.model import (
1112
attr, BaseXmlModel, computed_element, element, wrapped
1213
)
14+
from rich.table import Table
1315
from typer import Typer
1416
from typer.params import Argument
1517

@@ -52,10 +54,16 @@ def main(
5254
resp: Response = httpx.get(url=f"{BLOG_URL}/feed.xml")
5355
xml: bytes = resp.content
5456
model = Feed.from_xml(source=xml)
55-
json_string = model.model_dump_json()
5657

57-
with readme.open(mode="a") as f:
58-
f.write(f"result={json_string}\n")
58+
with readme.open(mode="r") as f:
59+
text = f.read()
60+
61+
pattern = "(?<=\<\!\-\- BLOG START \-\-\>).*(?=\<\!\-\- BLOG END \-\-\>)"
62+
table = Table(*("Title", "Author", "Published"))
63+
table.add_row(*(f"[{model.entry.title}]({model.entry.link})", model.entry.author, model.entry.published))
64+
text = re.sub(pattern=pattern, repl=str(table), string=text)
65+
with readme.open(mode="w") as f:
66+
f.write(text)
5967

6068

6169
if __name__ == "__main__":

.github/workflows/recent-posts.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717

1818
- name: Commit README
1919
run: |
20-
echo $(git diff --name-only)
2120
git config user.email [email protected]
2221
git config user.name github-actions
2322
git add .

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ Get help: [Post in our discussion board](https://github.com/orgs/skills/discussi
5555
&copy; 2023 GitHub &bull; [Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/code_of_conduct.md) &bull; [MIT License](https://gh.io/mit)
5656

5757
</footer>
58-
result={"entry":{"title":"pydantic-xml: Parsing My RSS Feed","relative_url":"/2024/12/23/pydantic-xml.html","published":"2024-12-23T00:00:00Z","updated":"2024-12-23T00:00:00Z","author":"Ian Thompson","link":"https://it176131.github.io/2024/12/23/pydantic-xml.html"}}
58+
59+
<!-- BLOG START -->
60+
<!-- BLOG END -->

0 commit comments

Comments
 (0)