Skip to content

Commit bdd79e2

Browse files
committed
.
Add DYNAMIC variable to environment Print message for already existing question in red color
1 parent e745288 commit bdd79e2

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/arguments/utility.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ def __init__(self):
3939
self.linux_path = "/home/{}/Documents/dynamic".format(os.getenv('USER'))
4040
self.mac_path = "/Users/{}/Documents/dynamic".format(os.getenv('USER'))
4141
self.file_name = 'dynamic_playbook.json'
42+
self.key = 'DYNAMIC'
4243

4344
@property
4445
def playbook_path(self):
45-
if(sys.platform=='linux'):
46-
return os.path.join(self.linux_path, self.file_name)
47-
if(sys.platform=='darwin'):
48-
return os.path.join(self.mac_path, self.file_name)
46+
# Create an environment variable 'DYNAMIC' containing the path of dynamic_playbook.json and returns it
47+
if not os.getenv(self.key):
48+
if(sys.platform=='linux'):
49+
os.environ[self.key] = os.path.join(self.linux_path, self.file_name)
50+
elif(sys.platform=='darwin'):
51+
os.environ[self.key] = os.path.join(self.mac_path, self.file_name)
52+
return os.getenv(self.key)
4953

5054
@property
5155
def playbook_template(self):
@@ -66,23 +70,6 @@ def playbook_content(self):
6670

6771
@playbook_content.setter
6872
def playbook_content(self, value):
69-
"""
70-
Saves playbook in the following format
71-
{
72-
time_of_update: unix,
73-
items_stackoverflow:
74-
[
75-
{
76-
time: unix timestamp
77-
question_id: 123456,
78-
question_title: 'question_title',
79-
question_link: 'link',
80-
answer_body: 'body of the answer'
81-
},
82-
...
83-
]
84-
}
85-
"""
8673
if isinstance(value, dict):
8774
with open(self.playbook_path, 'w') as playbook:
8875
json.dump(value, playbook, ensure_ascii=False)
@@ -100,9 +87,23 @@ def add_to_playbook(self, stackoverflow_object, question_id):
10087
"""
10188
Receives a QuestionsPanelStackoverflow object and
10289
saves data of a particular question into playbook
90+
Saves playbook in the following format
91+
{
92+
time_of_update: unix,
93+
items_stackoverflow:
94+
[
95+
{
96+
time: unix timestamp
97+
question_id: 123456,
98+
question_title: 'question_title',
99+
question_link: 'link',
100+
answer_body: 'body of the answer'
101+
},
102+
...
103+
]
103104
"""
104105
if self.is_question_in_playbook(question_id):
105-
SearchError("Question is already in the playbook", "No need to add")
106+
console.print("[red] Question is already in the playbook, No need to add")
106107
return
107108
for question in stackoverflow_object.questions_data:
108109
if(int(question[1])==int(question_id)):

0 commit comments

Comments
 (0)