Skip to content

Commit

Permalink
modified: .github/actions/recent-posts/main.py
Browse files Browse the repository at this point in the history
	- 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
  • Loading branch information
it176131 committed Jan 3, 2025
1 parent fab493a commit 2c8ce53
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions .github/actions/recent-posts/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from os import environ
import re
import subprocess
from typing import Annotated, Final

Expand All @@ -10,6 +11,7 @@
from pydantic_xml.model import (
attr, BaseXmlModel, computed_element, element, wrapped
)
from rich.table import Table
from typer import Typer
from typer.params import Argument

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

with readme.open(mode="a") as f:
f.write(f"result={json_string}\n")
with readme.open(mode="r") as f:
text = f.read()

pattern = "(?<=\<\!\-\- BLOG START \-\-\>).*(?=\<\!\-\- BLOG END \-\-\>)"
table = Table(*("Title", "Author", "Published"))
table.add_row(*(f"[{model.entry.title}]({model.entry.link})", model.entry.author, model.entry.published))
text = re.sub(pattern=pattern, repl=str(table), string=text)
with readme.open(mode="w") as f:
f.write(text)


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/recent-posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:

- name: Commit README
run: |
echo $(git diff --name-only)
git config user.email [email protected]
git config user.name github-actions
git add .
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ Get help: [Post in our discussion board](https://github.com/orgs/skills/discussi
&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)

</footer>
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"}}

<!-- BLOG START -->
<!-- BLOG END -->

0 comments on commit 2c8ce53

Please sign in to comment.