works now

This commit is contained in:
deadvey 2025-03-29 20:41:53 +00:00
parent 146acbecb0
commit f9a9166bb6
7 changed files with 36 additions and 26 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
config.py
__pycache__
*.swp
log

19
create_pages.py Executable file → Normal file
View File

@ -15,10 +15,12 @@
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")
@ -27,18 +29,17 @@ def create_user_page(userID, username, db):
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_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")

View File

@ -7,10 +7,14 @@ posts_in_timeline = 100
### SQL settings ###
host = "localhost"
user = "root"
user = "username"
password = "password"
database = "glogger"
### Logging ###
logfile = "/path/to/logfile"
verbose = False
### Format ###
# The syntax for this is pretty simple
# %S - post seperator as defined by post_seperator

10
newpost.py Executable file → Normal file
View File

@ -25,11 +25,13 @@ import click # Used to write post content, it launches a text editor to type int
# Other python files #
import create_pages
import config
import rebuild
def newpost(db, userID, username, datetime):
title = input("Title: ")
content = click.edit()
content = content.replace("'", "&#39")
content = content.replace("\n", "\\n")
print(content)
datetime = datetime.now().strftime("%d%m%YZ%H%M%ST")
@ -39,9 +41,5 @@ def newpost(db, userID, username, datetime):
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)
# Rebuild the config
rebuild.rebuild(db)

6
output.py Normal file
View File

@ -0,0 +1,6 @@
import config
def log(text):
if config.verbose == True:
print(text)
with open(config.logfile, "w") as logfile:
logfile.write(f"{text}\n")

0
parse_post.py Executable file → Normal file
View File

View File

@ -6,6 +6,6 @@ def rebuild(db):
for x in cursor:
create_pages.create_user_page(x[0], x[1], db)
create_pages.create_timeline(db)
cursor.execute('SELECT * FROM posts')
cursor.execute('SELECT posts.postID, users.username, posts.title, posts.content, posts.pubDate, posts.editDate FROM posts JOIN users ON posts.userID=users.userID')
for x in cursor:
create_pages.create_post_page(x[0], db)
create_pages.create_post_page(x, db)