forked from aeilot/aeilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-readme.py
39 lines (34 loc) · 1.15 KB
/
build-readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import feedparser
import os
from github import Github
import pathlib
import re
root = pathlib.Path(__file__).parent.resolve()
TOKEN = os.environ.get("TOKEN", "")
def replace_chunk(content, marker, chunk, inline=False):
r = re.compile(
r"<!\-\- {} starts \-\->.*<!\-\- {} ends \-\->".format(marker, marker),
re.DOTALL,
)
if not inline:
chunk = "\n{}\n".format(chunk)
chunk = "<!-- {} starts -->{}<!-- {} ends -->".format(marker, chunk, marker)
return r.sub(chunk, content)
def fetch_blog_entries():
entries = feedparser.parse("https://blog.aeilot.top/index.xml")["entries"]
return [
{
"title": entry["title"],
"url": entry["link"].split("#")[0],
"published": entry["published"].split("T")[0],
}
for entry in entries
]
if __name__ == "__main__":
readme = root / "README.md"
entries = fetch_blog_entries()[:5]
entries_md = "\n".join(
["* [{title}]({url}) - {published}".format(**entry) for entry in entries]
)
readme_contents = readme.open(encoding='UTF-8').read()
rewritten = replace_chunk(readme_contents, "blog", entries_md)