blog.ari.lt/scripts/v1-to-v2.py
Ari Archer f3145db1e0
update @ Thu Dec 26 04:29:22 EET 2024
Signed-off-by: Ari Archer <ari@ari.lt>
2024-12-26 04:29:22 +02:00

42 lines
1,021 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""migrates from v1 to v2"""
import json
from warnings import filterwarnings as filter_warnings
def t(data: str) -> str:
return data[:196] + ("" if len(data) < 196 else " ...")
def main() -> int:
"""entry / main function"""
with open("a.json", "r") as f: # old v1 blog
posts = json.load(f)["blogs"]
with open("blog.json", "r") as f:
blog = json.load(f)
for slug, post in posts.items():
blog["posts"][slug] = {
"title": post["title"],
"description": t(post["content"][:196]),
"content": post["content"],
"keywords": post["keywords"].split(),
"created": post["time"],
}
with open("blog.json", "w") as f:
json.dump(blog, f, indent=4)
return 0
if __name__ == "__main__":
assert main.__annotations__.get("return") is int, "main() should return an integer"
filter_warnings("error", category=Warning)
raise SystemExit(main())