#!/usr/bin/env python3 import asyncio import os, subprocess import markdown from bs4 import BeautifulSoup as bs async def main() -> int: open("/tmp/blog.md", "w").close() blog_title = input("Blog title: ") input( "Now this script will open your editor, enter the markdown you want in your blog there. press enter to continue" ) if os.getenv("EDITOR"): os.system(f"{os.getenv('EDITOR')} /tmp/blog.md") else: os.system(f"{input('What editor should I use?: ')} /tmp/blog.md") with open("/tmp/blog.md", "r") as f: blog_content = f.read() date = subprocess.check_output(["date", "+%F %T %Z"]).decode().rstrip("\n") content = f"""# %s {date} | [back](..) | [home](/) | [git](//github.com/TruncatedDinosour/website)
%s""" % ( blog_title, blog_content, ) with open( f"./page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html", "w" ) as f: f.write( f""" Ari::web -> Blog
%s
""" % (blog_title, markdown.markdown(content)) ) with open("./page/blog/index.md", "a") as f: f.write( f"\n* [{blog_title}](/page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html)" ) with open("./page/blog/index.html", "w") as f: with open("./page/blog/index.md", "r") as md: f.write( """ Ari::web -> Blog

My blogs

%s
""" % markdown.markdown(md.read()) ) # Pretify the blog and the index page with open("./page/blog/index.html", "r") as f: index_page = f.read() with open("./page/blog/index.html", "w") as f: soup = bs(index_page, features="lxml") f.write(soup.prettify()) with open(f"./page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html", "r") as f: blog_page = f.read() with open(f"./page/blog/blogs/{blog_title.replace(' ', '-').replace('/', '_')}.html", "w") as f: soup = bs(blog_page, features="lxml") f.write(soup.prettify()) return 0 if __name__ == "__main__": assert main.__annotations__.get("return") is int, "main() should return an integer" exit(asyncio.run(main()))