# File tree: # # / -- index.gmi # | # |- post/ -- 1.gmi # | | # | |- 2.gmi # | | # | |- 3.gmi # | # |- user/ -- deadvey.gmi # | # |- max.gmi # import config import parse_post import output from datetime import datetime def create_user_page(userID, username, db): with open(f"{config.webroot}/user/{username}.gmi", "w") as userfile: output.log("Writing posts to userfile") cursor = db.cursor() cursor.execute(f"SELECT * FROM posts WHERE userID = {userID} ORDER BY postID Desc") userfile.write(f"# {username}:\n") for x in cursor: post = config.user_page_post_format post = parse_post.parse_post_format(post, x, username) userfile.write(post) def create_post_page(post, db): with open(f"{config.webroot}/post/{post[0]}.gmi", "w") as postfile: output.log("Writing post to postfile") output.log(post) postfile_content = config.post_page_post_format postfile_content = parse_post.parse_post_format(postfile_content, post, post[1]) postfile.write(postfile_content) def create_timeline(db): with open(f"{config.webroot}/index.gmi", "w") as timeline_file: output.log("Writing posts to timeline") users = [] cursor = db.cursor() cursor.execute(f"SELECT userName FROM users") for x in cursor: users += x cursor.execute(f"SELECT * FROM posts ORDER BY postID Desc LIMIT {config.posts_in_timeline}") for x in cursor: username = users[x[1]-1] post = config.timeline_post_format post = parse_post.parse_post_format(post, x, username) timeline_file.write(post)