-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_readme.py
45 lines (35 loc) 路 1.22 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
40
41
42
43
44
45
from pathlib import Path
import feedparser
import requests
from bs4 import BeautifulSoup
def main():
chunks = []
chunks.extend(get_bio())
chunks.append('')
chunks.extend(get_latest_posts())
readme = Path(__file__).parent / "README.md"
readme.write_text("\n".join(chunks))
def get_bio():
# Get bio from my website to avoid duplication
response = requests.get("https://adamj.eu")
if response.status_code != 200:
raise ValueError("Unexpected response status code {response.status_code}")
soup = BeautifulSoup(response.content.decode(), "html.parser")
heading = soup.body.find("div", id="me").find("h2")
for elem in heading.next_siblings:
if elem.name == "h2":
break
if elem.name != "img" and str(elem).strip():
yield str(elem).replace("welcome to my site", "welcome to my GitHub bio")
def get_latest_posts():
chunks = ["## Latest blog posts\n"]
posts = feedparser.parse("https://adamj.eu/tech/atom.xml")["entries"][:5]
chunks.extend(
[
f'* [{post["title"]}]({post["link"]}) ({post["updated"].split("T")[0]})'
for post in posts
]
)
return chunks
if __name__ == "__main__":
main()