able to edit previous posts
This commit is contained in:
parent
a3914aab97
commit
ff180bf11e
11
README.md
11
README.md
@ -2,15 +2,8 @@ I've written a basic program in python called glogger, it is a customisable, sta
|
|||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
## Requirements:
|
## Requirements:
|
||||||
mysql-connector-python
|
* click: `pip install click`
|
||||||
mariadb-client
|
|
||||||
mariadb-server
|
|
||||||
## Database setup
|
|
||||||
``` CREATE DATABASE glogger;
|
|
||||||
USE glogger;
|
|
||||||
CREATE TABLE users ( userID INT PRIMARY KEY AUTO_INCREMENT NOT NULL, username VARCHAR(255) );
|
|
||||||
CREATE TABLE posts ( postID INT PRIMARY KEY AUTO_INCREMENT NOT NULL, userID INT, FOREIGN KEY(userID) REFERENCES users(userID), title VARCHAR(255), content VARCHAR(MAX), pubDate VARCHAR(255), editDate VARCHAR(255) );
|
|
||||||
```
|
|
||||||
# TO DO
|
# TO DO
|
||||||
* Add RSS and/or ATOM support
|
* Add RSS and/or ATOM support
|
||||||
* Make it more reliable?
|
* Make it more reliable?
|
||||||
|
49
editpost.py
Normal file
49
editpost.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import users
|
||||||
|
import posts
|
||||||
|
import rebuild
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
def editpost(userID, datetime):
|
||||||
|
post_counter = 0
|
||||||
|
user_posts = []
|
||||||
|
print("Which post do you want to edit?")
|
||||||
|
for current_post_index in range(len(posts.posts)):
|
||||||
|
if posts.posts[current_post_index]["userID"] == userID:
|
||||||
|
print(f"{post_counter}: {posts.posts[current_post_index]['title']}")
|
||||||
|
post_counter += 1
|
||||||
|
user_posts.append(posts.posts[current_post_index])
|
||||||
|
|
||||||
|
try:
|
||||||
|
post_to_edit_index = int(input())
|
||||||
|
except:
|
||||||
|
print("Failed to read input, did you input a number?")
|
||||||
|
|
||||||
|
print(f'''You selected:
|
||||||
|
Title: {posts.posts[post_to_edit_index]['title']}
|
||||||
|
Content: {posts.posts[post_to_edit_index]['content']}
|
||||||
|
''')
|
||||||
|
print('''0. Edit post's (T)itle
|
||||||
|
1. Edit post's (C)ontent
|
||||||
|
2. (D)elete post''')
|
||||||
|
answer = input()
|
||||||
|
|
||||||
|
if answer == "0" or answer == "T": # Editing the title
|
||||||
|
posts.posts[post_to_edit_index]['title'] = click.edit(posts.posts[post_to_edit_index]['title'])
|
||||||
|
posts.posts[post_to_edit_index]['editdate'] = datetime.now().strftime("%d%m%YZ%H%M%ST")
|
||||||
|
|
||||||
|
elif answer == "1" or answer == "C": # Editing the content
|
||||||
|
posts.posts[post_to_edit_index]['content'] = click.edit(posts.posts[post_to_edit_index]['content'])
|
||||||
|
posts.posts[post_to_edit_index]['editdate'] = datetime.now().strftime("%d%m%YZ%H%M%ST")
|
||||||
|
|
||||||
|
elif answer == "2" or answer == "D": # Editing the existence
|
||||||
|
print("Are you sure you want to delete it? There is no undoing!\n(Y/n)")
|
||||||
|
if input().upper() == "Y":
|
||||||
|
posts.posts.pop(post_to_edit_index)
|
||||||
|
else:
|
||||||
|
exit()
|
||||||
|
|
||||||
|
with open("posts.py", "w") as posts_file:
|
||||||
|
posts_file.write(f"posts = {posts.posts}")
|
||||||
|
|
||||||
|
rebuild.rebuild()
|
38
glogger.py
38
glogger.py
@ -1,4 +1,9 @@
|
|||||||
import initialise
|
import initialise
|
||||||
|
try:
|
||||||
|
import posts
|
||||||
|
except:
|
||||||
|
print("No posts database")
|
||||||
|
initialise.initialise()
|
||||||
try:
|
try:
|
||||||
import users
|
import users
|
||||||
except:
|
except:
|
||||||
@ -6,9 +11,26 @@ except:
|
|||||||
initialise.initialise()
|
initialise.initialise()
|
||||||
import config
|
import config
|
||||||
import newpost
|
import newpost
|
||||||
|
import editpost
|
||||||
import rebuild
|
import rebuild
|
||||||
|
|
||||||
|
import sys # Command line arguments
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
for argument in sys.argv:
|
||||||
|
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
|
||||||
|
''')
|
||||||
|
exit()
|
||||||
|
if argument == "--rebuild":
|
||||||
|
rebuild.rebuild()
|
||||||
|
exit()
|
||||||
|
|
||||||
username = input("Username: ").lower()
|
username = input("Username: ").lower()
|
||||||
|
|
||||||
# Check if this user exists
|
# Check if this user exists
|
||||||
@ -18,14 +40,14 @@ for current_user in range(len(users.users)):
|
|||||||
user_present = True
|
user_present = True
|
||||||
userID = current_user
|
userID = current_user
|
||||||
if user_present == True:
|
if user_present == True:
|
||||||
print('''What do you want to do?
|
print('''What do you want to do?
|
||||||
1. Create (N)ew post
|
0. Create (N)ew post
|
||||||
2. (R)ebuild''')
|
1. (E)dit a post''')
|
||||||
|
|
||||||
answer = input()
|
answer = input()
|
||||||
if answer == 'N' or answer == '1':
|
if answer == 'N' or answer == '0':
|
||||||
newpost.newpost(userID, username, datetime)
|
newpost.newpost(userID, username, datetime)
|
||||||
if answer == 'R' or answer == '2':
|
if answer == 'E' or answer == '1':
|
||||||
rebuild.rebuild()
|
editpost.editpost(userID, datetime)
|
||||||
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')
|
||||||
|
20
newpost.py
20
newpost.py
@ -1,23 +1,3 @@
|
|||||||
# users:
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
# | Field | Type | Null | Key | Default | Extra |
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
# | userID | int(11) | NO | PRI | NULL | auto_increment |
|
|
||||||
# | userName | varchar(255) | NO | | NULL | |
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
#
|
|
||||||
# posts:
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
# | Field | Type | Null | Key | Default | Extra |
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
# | postID | int(11) | NO | PRI | NULL | auto_increment |
|
|
||||||
# | userID | int(11) | YES | MUL | NULL | |
|
|
||||||
# | title | varchar(255) | YES | | NULL | |
|
|
||||||
# | content | text | YES | | NULL | |
|
|
||||||
# | pubDate | varchar(255) | YES | | NULL | |
|
|
||||||
# | editDate | varchar(255) | YES | | NULL | |
|
|
||||||
# +----------+--------------+------+-----+---------+----------------+
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import click # Used to write post content, it launches a text editor to type into
|
import click # Used to write post content, it launches a text editor to type into
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user