nonetype bugfixes

This commit is contained in:
2022-04-12 21:26:52 +03:00
parent b3cd6512e3
commit e029918359
+4 -4
View File
@@ -17,28 +17,28 @@ class Meme:
def get_random_attachment(self) -> str or None:
attachments = self.meta.get('attachments')
if len(attachments) < 1:
if not attachments:
return None
return random.choice(self.flatten_meta(attachments))
def get_random_audio(self) -> str or None:
attachments = self.meta.get('attachments')
if len(attachments) < 1 or attachments.get('audio') is None:
if not attachments or attachments.get('audio') is None:
return None
return random.choice(attachments.get('audio'))
def get_random_video(self) -> str or None:
attachments = self.meta.get('attachments')
if len(attachments) < 1 or attachments.get('video') is None:
if not attachments or attachments.get('video') is None:
return None
return random.choice(attachments.get('video'))
@staticmethod
def flatten_meta(meta: dict[str, any]) -> list[str]:
return [a for k in [i for i in meta] for a in k]
return [a for k in [i for i in meta.values()] for a in k]
class Day: