Compare commits

...

6 Commits

7 changed files with 56 additions and 24 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
config.py
htmlconfig.py
__pycache__
*.swp
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.
=> 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
## Prerequisits:
* python3.12 or later (might work on other versions)
@@ -28,6 +33,8 @@ python3 glogger.py
```
# TO DO
* Activity Pub support
* Newsletter support
* Add ATOM support
* Properly comment everything
* Better logging to help debug

View File

@@ -9,19 +9,23 @@ def create_rss():
<rss version="2.0">
<channel>
<title>{config.site_name}</title>
<link>{config.site_url}</title>
<link>{config.site_url}</link>
<description>{config.site_description}</description>
<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>
'''
for current_post_index in range(len(posts.posts)):
for current_post_index in range(len(posts.posts)-1,-1,-1):
file_content += f'''
<item>
<title>{posts.posts[current_post_index]["title"]}</title>
<link>{config.site_url}/post/{current_post_index}.{config.file_extension}</link>
<description>{posts.posts[current_post_index]["content"]}</descriptiont>
<pubDate>{posts.posts[current_post_index]["pubdate"]}</pubDate>
<editDate>{posts.posts[current_post_index]["editdate"]}</editDate>
<description>{posts.posts[current_post_index]["content"]}</description>
<pubDate>
{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>'''
file_content += '''
</channel>

View File

@@ -1,10 +1,8 @@
import users
import posts
import rebuild
import click
def editpost(userID, datetime):
def editpost(userID, datetime, config, posts, users):
post_counter = 0
user_posts = []
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
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:
import posts
except:
@@ -10,33 +27,37 @@ except:
print("No users database")
initialise.initialise()
try:
import config
config = SourceFileLoader("config", config_file_path).load_module()
if config.autogenerated == True:
print("Error: autogenerated = True")
exit()
except:
print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False")
exit()
import newpost
import editpost
import rebuild
import sys # Command line arguments
from datetime import datetime
if len(sys.argv) > 1:
for argument in sys.argv:
if argument == "glogger.py":
continue
if argument == "--help":
print('''
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
''')
print(help_text)
exit()
if argument == "--rebuild":
rebuild.rebuild()
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()
@@ -53,8 +74,8 @@ if user_present == True:
answer = input()
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':
editpost.editpost(userID, datetime)
editpost.editpost(userID, datetime, config, posts, users)
else:
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")
import output
def newpost(userID, username, datetime):
def newpost(userID, username, datetime, config, posts, users):
title = input("Title: ")
content = click.edit()
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("%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("%H", f"{config.site_url}/")
post = post.replace("%N", username)
return post