64 lines
1.4 KiB
Python
Executable file
64 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
from functools import partial as p
|
|
from ipo import ipo, write, starstarmap
|
|
|
|
from page import blog_page_metadata
|
|
|
|
|
|
BASE_URL = "https://www.braindeaddev.com/P5t7oFqPF7oEX"
|
|
|
|
DOC_TEMPLATE = """<?xml version="1.0"?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>Midgard's blog</title>
|
|
<description></description>
|
|
<lastBuildDate>{last_updated}</lastBuildDate>
|
|
<author>Midgard</author>
|
|
<link>{url}</link>{0}
|
|
</channel>
|
|
</rss>"""
|
|
|
|
ITEM_TEMPLATE = """
|
|
<item>
|
|
<title>{title}</title>
|
|
<guid>{path}</guid>
|
|
<pubDate>{published_rfc822}</pubDate>
|
|
<link>{url}</link>
|
|
<description>{summary}</description>
|
|
</item>"""
|
|
# <category>{category}</category>
|
|
|
|
|
|
def iso8601torfc822(iso8601):
|
|
# pylint: disable=invalid-name
|
|
y, m, d = map(int, iso8601.split("-"))
|
|
month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][m]
|
|
return f"{d} {month} {y} 00:00:00 UTC"
|
|
|
|
|
|
def main():
|
|
items = (
|
|
ipo(sys.argv[1:]) |
|
|
p(map, blog_page_metadata) |
|
|
p(sorted, key=lambda x: x["published"]) |
|
|
p(map, lambda x: {
|
|
**x,
|
|
"published_rfc822": iso8601torfc822(x["published"]),
|
|
"url": f"{BASE_URL}/{x['path']}"
|
|
}) | list
|
|
)
|
|
|
|
last_date = items.data[-1]["published_rfc822"]
|
|
|
|
(
|
|
items |
|
|
p(starstarmap, ITEM_TEMPLATE.format) |
|
|
"".join |
|
|
p(DOC_TEMPLATE.format, url=BASE_URL, last_updated=last_date) |
|
|
write
|
|
)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|