-
Notifications
You must be signed in to change notification settings - Fork 0
/
word.py
27 lines (21 loc) · 954 Bytes
/
word.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import shutil
class Word:
def __init__(self, word: str, imagePath: str = None, definitions: list = None, exampleSentences: list = None):
self.word = word
self.imagePath = imagePath
self.imageExists = True
self.fileExtension = ''
if not os.path.exists(self.imagePath):
self.imageExists = False
self.copyImageToDataFolder()
self.definitions = definitions
self.exampleSentences = exampleSentences
def copyImageToDataFolder(self):
if not self.imageExists:
return
self.fileExtension = self.imagePath.split('.')[-1]
self.newImagePath = f'data/{self.word}.{self.fileExtension}'
shutil.copy2(self.imagePath, self.newImagePath)
def getAsDictionary(self):
return {'imageExists': self.imageExists,'definitions': self.definitions, 'exampleSentences': self.exampleSentences, 'fileExtension': self.fileExtension}