Compare commits

...

6 Commits

7 changed files with 56 additions and 24 deletions

1
.gitignore vendored
View File

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

View File

@@ -4,6 +4,11 @@ It is written in python and everytime a new post is made, that post is added to
Glogger uses this file to build a frontend with a customisable format. Glogger uses this file to build a frontend with a customisable format.
=> gemini://deadvey.com/gemlog Example of Glogger in action => gemini://deadvey.com/gemlog Example of Glogger in action
# Command line options
```--help``` Shows help text
```--rebuild``` Rewrite every static page in the site
```--config={configuration file}``` Specifiy the file path of the configuration file, default: config.py
# Setup # Setup
## Prerequisits: ## Prerequisits:
* python3.12 or later (might work on other versions) * python3.12 or later (might work on other versions)
@@ -28,6 +33,8 @@ python3 glogger.py
``` ```
# TO DO # TO DO
* Activity Pub support
* Newsletter support
* Add ATOM support * Add ATOM support
* Properly comment everything * Properly comment everything
* Better logging to help debug * Better logging to help debug

View File

@@ -9,19 +9,23 @@ def create_rss():
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title>{config.site_name}</title> <title>{config.site_name}</title>
<link>{config.site_url}</title> <link>{config.site_url}</link>
<description>{config.site_description}</description> <description>{config.site_description}</description>
<pubDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</pubDate> <pubDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</pubDate>
<lastBuildDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</lastBuildDate> <lastBuildDate>{datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}</lastBuildDate>
''' '''
for current_post_index in range(len(posts.posts)): for current_post_index in range(len(posts.posts)-1,-1,-1):
file_content += f''' file_content += f'''
<item> <item>
<title>{posts.posts[current_post_index]["title"]}</title> <title>{posts.posts[current_post_index]["title"]}</title>
<link>{config.site_url}/post/{current_post_index}.{config.file_extension}</link> <link>{config.site_url}/post/{current_post_index}.{config.file_extension}</link>
<description>{posts.posts[current_post_index]["content"]}</descriptiont> <description>{posts.posts[current_post_index]["content"]}</description>
<pubDate>{posts.posts[current_post_index]["pubdate"]}</pubDate> <pubDate>
<editDate>{posts.posts[current_post_index]["editdate"]}</editDate> {datetime.strptime(posts.posts[current_post_index]["pubdate"],"%d%m%YZ%H%M%ST").strftime("%a, %d %b %Y %H:%M:%S %z")}
</pubDate>
<editDate>
{datetime.strptime(posts.posts[current_post_index]["editdate"],"%d%m%YZ%H%M%ST").strftime("%a, %d %b %Y %H:%M:%S %z")}
</editDate>
</item>''' </item>'''
file_content += ''' file_content += '''
</channel> </channel>

View File

@@ -1,10 +1,8 @@
import users
import posts
import rebuild import rebuild
import click import click
def editpost(userID, datetime): def editpost(userID, datetime, config, posts, users):
post_counter = 0 post_counter = 0
user_posts = [] user_posts = []
print("Which post do you want to edit?") print("Which post do you want to edit?")

View File

@@ -1,4 +1,21 @@
import sys # Command line arguments
from importlib.machinery import SourceFileLoader
from datetime import datetime
import newpost
import editpost
import rebuild
import initialise import initialise
help_text = '''
If no argument is passed, glogger will ask for a username;
if that user exists, it will as if you want to create a new post, or edit a post (TODO)
--help Output this help text
--rebuild Rewrite every static page in the site
--config={configuration file path} Specify the file path of the configuration
'''
config_file_path = "config.py"
try: try:
import posts import posts
except: except:
@@ -10,33 +27,37 @@ except:
print("No users database") print("No users database")
initialise.initialise() initialise.initialise()
try: try:
import config config = SourceFileLoader("config", config_file_path).load_module()
if config.autogenerated == True: if config.autogenerated == True:
print("Error: autogenerated = True") print("Error: autogenerated = True")
exit() exit()
except: except:
print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False") print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False")
exit() exit()
import newpost
import editpost
import rebuild
import sys # Command line arguments
from datetime import datetime
if len(sys.argv) > 1: if len(sys.argv) > 1:
for argument in sys.argv: for argument in sys.argv:
if argument == "glogger.py":
continue
if argument == "--help": if argument == "--help":
print(''' print(help_text)
If no argument is passed, glogger will ask for a username;
if that user exists, it will as if you want to create a new post, or edit a post (TODO)
--help Output this help text
--rebuild Rewrite every static page in the site
''')
exit() exit()
if argument == "--rebuild": if argument == "--rebuild":
rebuild.rebuild() rebuild.rebuild()
exit() exit()
if argument[:9] == "--config=":
config_file_path = argument[9:]
try:
config = SourceFileLoader("config", config_file_path).load_module()
if config.autogenerated == True:
print("Error: autogenerated = True")
exit()
except:
print(f"{config_file_path} does not exist")
exit()
else:
print(f"Invalid Argument: {argument}")
print(help_text)
username = input("Username: ").lower() username = input("Username: ").lower()
@@ -53,8 +74,8 @@ if user_present == True:
answer = input() answer = input()
if answer == 'N' or answer == '0': if answer == 'N' or answer == '0':
newpost.newpost(userID, username, datetime) newpost.newpost(userID, username, datetime, config, posts, users)
if answer == 'E' or answer == '1': if answer == 'E' or answer == '1':
editpost.editpost(userID, datetime) editpost.editpost(userID, datetime, config, posts, users)
else: else:
print('Sorry, that account does not exist, If it should, please ask the webadmin to add this account') print('Sorry, that account does not exist, If it should, please ask the webadmin to add this account')

View File

@@ -15,7 +15,7 @@ except:
print("No users database") print("No users database")
import output import output
def newpost(userID, username, datetime): def newpost(userID, username, datetime, config, posts, users):
title = input("Title: ") title = input("Title: ")
content = click.edit() content = click.edit()
content = content.replace("'", "\'") content = content.replace("'", "\'")

View File

@@ -11,6 +11,7 @@ def parse_post_format(post, post_index, username):
post = post.replace("%C", post_data["content"]) post = post.replace("%C", post_data["content"])
post = post.replace("%L", f"{config.site_url}/post/{post_index}.{config.file_extension}") post = post.replace("%L", f"{config.site_url}/post/{post_index}.{config.file_extension}")
post = post.replace("%U", f"{config.site_url}/user/{username}.{config.file_extension}") post = post.replace("%U", f"{config.site_url}/user/{username}.{config.file_extension}")
post = post.replace("%H", f"{config.site_url}/")
post = post.replace("%N", username) post = post.replace("%N", username)
return post return post