works now
This commit is contained in:
parent
146acbecb0
commit
f9a9166bb6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
config.py
|
||||
__pycache__
|
||||
*.swp
|
||||
log
|
||||
|
35
create_pages.py
Executable file → Normal file
35
create_pages.py
Executable file → Normal file
@ -15,30 +15,31 @@
|
||||
|
||||
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:
|
||||
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)
|
||||
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(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")
|
||||
|
@ -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
10
newpost.py
Executable file → Normal 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("'", "'")
|
||||
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
6
output.py
Normal 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
0
parse_post.py
Executable file → Normal 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user