Repository navigation
Expand file tree
/
Copy pathclasses_old.py
More file actions
106 lines (90 loc) · 2.78 KB
/
Copy pathclasses_old.py
File metadata and controls
106 lines (90 loc) · 2.78 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class Bcolors:
HEAD = "\033[95m"
OK = "\033[92m"
FAIL = "\033[91m"
BOLD = "\033[1m"
END = "\033[0m"
class Master:
"""class that can be used as a parent for both items and locations"""
def __init__(self, description: str = None):
self.description = (
description.lower()
) # ensures consistency by lowering case of description
_adjectives: list[str] = get_part_of_speech(self.description)[
"adjectives"
] # strips out a list of adjectives
_noun: str = get_part_of_speech(self.description)["noun"]
_key: str = get_key(_adjectives, _noun)
self._noun = _noun
self._adjectives = _adjectives
self._key = _key
@classmethod
def get_key(cls, adjectives: list[str], noun: str):
word_list = []
for adjective in adjectives:
word_list.append(str(adjective).strip().lower())
word_list = word_list + noun
word_list.sort()
if word_list:
key = "_".join(word_list)
if len(key) > 0:
return key
else:
raise ValueError(
f"{Bcolors.FAIL}That is not a valid instruction - please try again or type 'help'{Bcolors.END}"
)
else:
raise ValueError(inv_help)
@property
def clean_desc(self):
adjectives = " ".join(self._adjectives)
noun = self.noun
if adjectives:
return f"{adjectives} {noun}"
else:
return f"{noun}"
def __str__(self):
return self.clean_desc
@property
def key(self):
return self._key
@property
def noun(self):
return self._noun
@property
def adjectives(self):
return self._adjectives
class Item(Master):
@property
def exists(self):
current_items = [item["item_key"] for item in items_list]
if self.key in current_items:
return True
else:
return False
def create_new(self):
items_list.append(
{
"item_key": self.key,
"noun": self.noun,
"adjectives": self.adjectives,
"description": self.clean_desc,
}
)
# class Location(Master):
# @property
# def exists(self):
# current_locations = [loc["location_key"] for loc in locations_list]
# if self.key in current_locations:
# return True
# else:
# return False
# def create_new(self):
# locations_list.append(
# {
# "location_key": self.key,
# "noun": self.noun,
# "adjectives": self.adjectives,
# "description": self.clean_desc,
# }
# )