# users: # +----------+--------------+------+-----+---------+----------------+ # | Field | Type | Null | Key | Default | Extra | # +----------+--------------+------+-----+---------+----------------+ # | userID | int(11) | NO | PRI | NULL | auto_increment | # | userName | varchar(255) | NO | | NULL | | # +----------+--------------+------+-----+---------+----------------+ # # posts: # +----------+--------------+------+-----+---------+----------------+ # | Field | Type | Null | Key | Default | Extra | # +----------+--------------+------+-----+---------+----------------+ # | postID | int(11) | NO | PRI | NULL | auto_increment | # | userID | int(11) | YES | MUL | NULL | | # | title | varchar(255) | YES | | NULL | | # | content | text | YES | | NULL | | # | pubDate | varchar(255) | YES | | NULL | | # | editDate | varchar(255) | YES | | NULL | | # +----------+--------------+------+-----+---------+----------------+ import mysql.connector from datetime import datetime import click # Used to write post content, it launches a text editor to type into # Other python files # import create_pages import config def newpost(db, userID, username, datetime): title = input("Title: ") content = click.edit() content = content.replace("'", "'") print(content) datetime = datetime.now().strftime("%d%m%YZ%H%M%ST") cursor = db.cursor() cursor.execute(f"INSERT INTO posts (userID, title, content, pubDate, editDate) VALUES({userID}, '{title}', '{content}', '{datetime}', '{datetime}')") cursor.execute(f"SELECT * FROM posts ORDER BY postID Desc LIMIT 1") for x in cursor: postID = x[0] db.commit() ## Write to user page ## create_pages.create_user_page(userID, username, db) create_pages.create_post_page(postID, username, db) create_pages.create_timeline(db)