Skip to content

Added oop task#9

Open
ibragimovaamina wants to merge 2 commits into
mainfrom
hw1_oop
Open

Added oop task#9
ibragimovaamina wants to merge 2 commits into
mainfrom
hw1_oop

Conversation

@ibragimovaamina

Copy link
Copy Markdown
Owner

No description provided.

@krglkvrmn krglkvrmn left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines +15 to +18
if start is None:
start = self.default_start
if end is None:
end = datetime.now()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я бы лучше использовал время первого и последних сообщений в качестве дефолтных дат, тем более, что их просто получить

Suggested change
if start is None:
start = self.default_start
if end is None:
end = datetime.now()
if start is None:
start = self._chat_history[-1].datetime
if end is None:
end = self._chat_history[0].datetime

Comment on lines +22 to +24
for message in self._chat_history:
if self.end >= message.datetime >= self.start:
print(message.show())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines +30 to +32
if isinstance(message, Message):
message.datetime = datetime.now() # Set attribute datetime when message is recieved by chat
self._chat_history.insert(0, message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В таких случаях лучше писать else в котором кидать исключение, так как юзер может получить None, передав не тот тип, и потом будет гадать, что пошло не так

Suggested change
if isinstance(message, Message):
message.datetime = datetime.now() # Set attribute datetime when message is recieved by chat
self._chat_history.insert(0, message)
if isinstance(message, Message):
message.datetime = datetime.now() # Set attribute datetime when message is recieved by chat
self._chat_history.insert(0, message)
else:
raise TypeError(f"Method does not support type {type(message)}")

Comment on lines +41 to +45
def show(self):
if self.datetime:
return f'{self.datetime} {self.user}: {self.text}'
else:
return f'{self.user}: {self.text}'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обычно функции, которые имеют в названии show, не возвращают, а показывают данные

Suggested change
def show(self):
if self.datetime:
return f'{self.datetime} {self.user}: {self.text}'
else:
return f'{self.user}: {self.text}'
def show(self):
if self.datetime:
print(f'{self.datetime} {self.user}: {self.text}')
else:
print(f'{self.user}: {self.text}')

Comment on lines +48 to +49
if isinstance(chat, Chat):
chat._recieve(self)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично предыдущему, но подход через такое взаимодействие send и recieve хороший



class User:
all_users = [] # List of all objects of class User

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants