Skip to content

#162539042 Add moderator user edit comment #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions commandblog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,87 +28,85 @@
}
]


def login():
username = input("please input username: ")

for user in users:
if user['name'] == username:
# return user['password']
password = input("please input password: ")
if user['password'] != password:
return 'Wrong password'
user["lastLoginAt"] = datetime.datetime.now()

if user['role'] == "normal":
userinput = input("1. create comment \n 2.Edit comment \n 3. logout ")

if userinput == str("1"):
comment = input("Enter your comment:")
data = {'comment_id': len(comments) +1,
'comment': comment,
'timestamp': datetime.datetime.now() ,
'created_by': username
}

data = {'comment_id': len(comments) + 1,
'comment': comment,
'timestamp': datetime.datetime.now(),
'created_by': username
}
comments.append(data)
return comments

elif userinput == str("2"):
comment_id = int(input('Enter comment id:'))
if not comment_id:
return "Enter comment id"
comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False)
comment = next(
(comment for comment in comments if comment["comment_id"] == comment_id), False)
if comment == False:
return "No comment found"
return "No comment found"
edit = input("Enter your comment here:")
comment["comment"] = edit
return comments

else:
login()


if user['role'] == "moderator":
userinput = input("1. create comment \n 2. edit comment \n 3. delete comment \n 4. logout \n ")
elif user['role'] == "moderator":
userinput = input(
"1. create comment \n 2. edit comment \n 3. delete comment \n 4. logout \n ")

if userinput == str("1"):
comment = input("Enter your comment:")
data = {'comment_id': len(comments) +1,
'comment': comment,
'timestamp': datetime.datetime.now() ,
'created_by': username
}

data = {'comment_id': len(comments) + 1,
'comment': comment,
'timestamp': datetime.datetime.now(),
'created_by': username
}
comments.append(data)
return comments

elif userinput == str("2"):
comment_id = int(input('Enter comment id:'))
if not comment_id:
return "Enter comment id: "
comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False)
comment = next(
(comment for comment in comments if comment["comment_id"] == comment_id), False)
if comment == False:
return "No comment found"
return "No comment found"
edit = input("Enter your comment here:")
comment["comment"] = edit
return comments
elif userinput == str("3"):
comment_id = int(input('Enter comment id'))
if not comment_id:
return 'Enter comment id'
comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False)
comment = next(
(comment for comment in comments if comment["comment_id"] == comment_id), False)
if comment == False:
return "No comment found"
return "No comment found"
comments.remove(comment)
return comments


else:
login()






print(login())
print(login())