works now
This commit is contained in:
parent
146acbecb0
commit
f9a9166bb6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
config.py
|
config.py
|
||||||
__pycache__
|
__pycache__
|
||||||
*.swp
|
*.swp
|
||||||
|
log
|
||||||
|
19
create_pages.py
Executable file → Normal file
19
create_pages.py
Executable file → Normal file
@ -15,10 +15,12 @@
|
|||||||
|
|
||||||
import config
|
import config
|
||||||
import parse_post
|
import parse_post
|
||||||
|
import output
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
def create_user_page(userID, username, db):
|
def create_user_page(userID, username, db):
|
||||||
with open(f"{config.webroot}/user/{username}.gmi", "w") as userfile:
|
with open(f"{config.webroot}/user/{username}.gmi", "w") as userfile:
|
||||||
|
output.log("Writing posts to userfile")
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute(f"SELECT * FROM posts WHERE userID = {userID} ORDER BY postID Desc")
|
cursor.execute(f"SELECT * FROM posts WHERE userID = {userID} ORDER BY postID Desc")
|
||||||
userfile.write(f"# {username}:\n")
|
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)
|
post = parse_post.parse_post_format(post, x, username)
|
||||||
userfile.write(post)
|
userfile.write(post)
|
||||||
|
|
||||||
def create_post_page(postID, db):
|
def create_post_page(post, db):
|
||||||
with open(f"{config.webroot}/post/{postID}.gmi", "w") as postfile:
|
with open(f"{config.webroot}/post/{post[0]}.gmi", "w") as postfile:
|
||||||
cursor = db.cursor()
|
output.log("Writing post to postfile")
|
||||||
cursor.execute(f"SELECT * FROM posts WHERE postID = {postID}")
|
output.log(post)
|
||||||
cursor2 = db.cursor()
|
postfile_content = config.post_page_post_format
|
||||||
cursor2.execute('SELECT * FROM users')
|
postfile_content = parse_post.parse_post_format(postfile_content, post, post[1])
|
||||||
post = config.post_page_post_format
|
postfile.write(postfile_content)
|
||||||
post = parse_post.parse_post_format(post, x, cursor2[cursor[0]-1][1])
|
|
||||||
postfile.write(post)
|
|
||||||
|
|
||||||
def create_timeline(db):
|
def create_timeline(db):
|
||||||
with open(f"{config.webroot}/index.gmi", "w") as timeline_file:
|
with open(f"{config.webroot}/index.gmi", "w") as timeline_file:
|
||||||
|
output.log("Writing posts to timeline")
|
||||||
users = []
|
users = []
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute(f"SELECT userName FROM users")
|
cursor.execute(f"SELECT userName FROM users")
|
||||||
|
@ -7,10 +7,14 @@ posts_in_timeline = 100
|
|||||||
|
|
||||||
### SQL settings ###
|
### SQL settings ###
|
||||||
host = "localhost"
|
host = "localhost"
|
||||||
user = "root"
|
user = "username"
|
||||||
password = "password"
|
password = "password"
|
||||||
database = "glogger"
|
database = "glogger"
|
||||||
|
|
||||||
|
### Logging ###
|
||||||
|
logfile = "/path/to/logfile"
|
||||||
|
verbose = False
|
||||||
|
|
||||||
### Format ###
|
### Format ###
|
||||||
# The syntax for this is pretty simple
|
# The syntax for this is pretty simple
|
||||||
# %S - post seperator as defined by post_seperator
|
# %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 #
|
# Other python files #
|
||||||
import create_pages
|
import create_pages
|
||||||
import config
|
import config
|
||||||
|
import rebuild
|
||||||
|
|
||||||
def newpost(db, userID, username, datetime):
|
def newpost(db, userID, username, datetime):
|
||||||
title = input("Title: ")
|
title = input("Title: ")
|
||||||
content = click.edit()
|
content = click.edit()
|
||||||
content = content.replace("'", "'")
|
content = content.replace("'", "'")
|
||||||
|
content = content.replace("\n", "\\n")
|
||||||
print(content)
|
print(content)
|
||||||
datetime = datetime.now().strftime("%d%m%YZ%H%M%ST")
|
datetime = datetime.now().strftime("%d%m%YZ%H%M%ST")
|
||||||
|
|
||||||
@ -39,9 +41,5 @@ def newpost(db, userID, username, datetime):
|
|||||||
for x in cursor:
|
for x in cursor:
|
||||||
postID = x[0]
|
postID = x[0]
|
||||||
db.commit()
|
db.commit()
|
||||||
## Write to user page ##
|
# Rebuild the config
|
||||||
create_pages.create_user_page(userID, username, db)
|
rebuild.rebuild(db)
|
||||||
create_pages.create_post_page(postID, username, db)
|
|
||||||
create_pages.create_timeline(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:
|
for x in cursor:
|
||||||
create_pages.create_user_page(x[0], x[1], db)
|
create_pages.create_user_page(x[0], x[1], db)
|
||||||
create_pages.create_timeline(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:
|
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