Skip to content
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
99 changes: 59 additions & 40 deletions commandblog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,93 +22,112 @@
"lastLoginAt": ""
},
{
"name": "steve",
"name": "stev",
"password": "1234",
"role": "normal"
}
]


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

if not username:
print('please input username !!!')
return "please input username!!!"
if not password:
print('please input password !!!')
return "please input password!!!"
user = next((user for user in users if user["name"] == username), False)

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 == False:
print('No user with that username exists')
return 'No user with that username exists'

if user['password'] != password:
print('wrong 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
print(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
print(comments)

else:
login()


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

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
print(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)
print("Enter comment id: ")
comment = next(
(comment for comment in comments if comment["comment_id"] == comment_id), False)
if comment == False:
return "No comment found"
print("No comment found")
edit = input("Enter your comment here:")
comment["comment"] = edit
return comments
print(comments)

elif userinput == str("3"):
comment_id = int(input('Enter comment id'))
comment_id = int(input("Enter the comment id to delete:"))
if not comment_id:
return 'Enter comment id'
print('You must enter the comment id')
comment = next((comment for comment in comments if comment["comment_id"] == comment_id), False)

if comment == False:
return "No comment found"
print('Comment not found!')
comments.remove(comment)
return comments

print(comments)

else:
login()


if __name__ == "__main__":


choice = 'y'

while choice is not 'n':

login()

print(login())
choice = input('Continue?')