# File tree: # # / -- index.gmi # | # |- post/ -- 1.gmi # | | # | |- 2.gmi # | | # | |- 3.gmi # | # |- user/ -- deadvey.gmi # | # |- max.gmi # import config import parse_post from datetime import datetime def create_user_page(userID, username, db): with open(f"{config.webroot}/user/{username}.gmi", "w") as 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(postID, db): with open(f"{config.webroot}/post/{postID}.gmi", "w") as postfile: cursor = db.cursor() cursor.execute(f"SELECT * FROM posts WHERE postID = {postID}") cursor2 = db.cursor() cursor2.execute('SELECT * FROM users') post = config.post_page_post_format post = parse_post.parse_post_format(post, x, cursor2[cursor[0]-1][1]) postfile.write(post) def create_timeline(db): with open(f"{config.webroot}/index.gmi", "w") as timeline_file: 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)