mirror of
https://github.com/shadoll/playing_now_2_mm.git
synced 2026-02-04 11:03:23 +00:00
code refactoring
This commit is contained in:
@@ -3,25 +3,35 @@ import random
|
||||
import emoji
|
||||
|
||||
|
||||
class Random:
|
||||
class RandomConnector:
|
||||
def __init__(self):
|
||||
self.faker = Faker()
|
||||
self.__faker = Faker()
|
||||
|
||||
def get_random_activity(self) -> tuple:
|
||||
activity = self.faker.bs().capitalize() # Generate a random activity
|
||||
emoji = self.get_random_emoji_name() # Get a random emoji
|
||||
duration = random.randint(5, 60) # Duration in minutes
|
||||
return activity, emoji, duration
|
||||
@property
|
||||
def text(self) -> str:
|
||||
return self.__faker.bs().capitalize()
|
||||
|
||||
def get_random_emoji_name(self) -> str:
|
||||
@property
|
||||
def emoji(self) -> dict:
|
||||
emoji_names = list(emoji.get_aliases_unicode_dict())
|
||||
single_char_emoji_names = [
|
||||
name for name in emoji_names if len(emoji.emojize(name)) == 1
|
||||
]
|
||||
random_emoji_name = random.choice(single_char_emoji_names)
|
||||
return random_emoji_name
|
||||
emoji_name = random.choice(single_char_emoji_names)
|
||||
return {
|
||||
"name": emoji_name.replace(":", ""),
|
||||
"name_with_colons": emoji_name,
|
||||
"icon": emoji.emojize(emoji_name),
|
||||
}
|
||||
|
||||
def get_random_emoji(self) -> str:
|
||||
random_emoji = emoji.emojize(self.get_random_emoji_name())
|
||||
@property
|
||||
def duration(self) -> int:
|
||||
"""Return a random duration between 5 and 60 minutes in seconds"""
|
||||
return random.randint(5, 60) * 60
|
||||
|
||||
return random_emoji
|
||||
def get(self) -> dict:
|
||||
return {
|
||||
name: getattr(self, name)
|
||||
for name in dir(self)
|
||||
if not name.startswith("_") and not callable(getattr(self, name))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user