-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss.py
36 lines (31 loc) · 1.02 KB
/
rss.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
from pathlib import Path
import jinja2
from typing import Any
from datetime import datetime, UTC
root_dir = Path(__file__).parent
template_path = root_dir / "template.rss.jinja"
result_rss_path = root_dir / "releases.rss"
channel = dict(
title="DF steam news",
link="https://store.steampowered.com/news/app/975370",
description="DF steam news",
)
def write_rss(post: dict[str, Any]) -> str:
template_text = template_path.read_text(encoding="utf-8")
template = jinja2.Template(template_text)
pub_date = datetime.fromtimestamp(post["date"], tz=UTC)
rendered = template.render(
dict(
channel=channel,
items=[
dict(
title=post["title"],
pub_date=pub_date.strftime("%a, %d %b %Y %H:%M:%S %z"),
link=post["url"],
description=post["contents"],
guid=post["gid"],
),
],
),
)
result_rss_path.write_text(rendered, encoding="utf-8")