GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — jiangyangcreate/build_readme.py at main · jiangyangcreate/jiangyangcreate

Expand file tree

/

build_readme.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
48 lines (39 loc) · 1.43 KB
/

build_readme.py

Copy path

File metadata and controls

48 lines (39 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
import time
import pathlib
import requests
import feedparser
from jinja2 import Environment, FileSystemLoader
RSS = "https://jiangmiemie.com/blog/rss.xml"
ROOT = pathlib.Path(__file__).parent.resolve()
JINJA_DIR = ROOT / "jinja"
TEMPLATES = ("README", "README_zh")
jinja_env = Environment(loader=FileSystemLoader(JINJA_DIR))
def fetch_blog(page_num: int = 5) -> str:
entries = feedparser.parse(RSS)["entries"][:page_num]
lines = []
for entry in entries:
title = entry["title"]
url = entry["link"].split("#")[0]
published = time.strftime("%Y-%m-%d", entry["published_parsed"])
lines.append(f"* <a href='{url}' target='_blank'>{title}</a> - {published}")
return "\n".join(lines)
def fetch_weather(city: str = "shenzhen", timeout: int = 5) -> str:
try:
raw = requests.get(
f"https://wttr.in/{city}?m&format=3", timeout=timeout
).text
return raw.split(":", 1)[1].replace("\n", "").strip()
except Exception:
return "⛅️ 0°C"
def build_readmes() -> None:
context = {
# "weather": fetch_weather(),
"blog": fetch_blog(),
"fetch": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
}
for name in TEMPLATES:
content = jinja_env.get_template(f"{name}.jinja").render(context)
output = ROOT / f"{name}.md"
output.write_text(content, encoding="utf-8")
if __name__ == "__main__":
build_readmes()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.