Skip to content

Commit 51d4fe3

Browse files
committed
Revert "Change code style to PEP8"
This reverts commit 2005aaa. Revert master branch to non PEP8 version
1 parent 2005aaa commit 51d4fe3

File tree

5 files changed

+40
-99
lines changed

5 files changed

+40
-99
lines changed

src/arguments/api_test.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def get_request(cls):
3030
# Ask the user for endpoint if not present in request_url
3131
if not(has_endpoint):
3232
if(request_url[-1] == '/'):
33-
endpoint = input("Input endpoint \
34-
(Without the starting slash): ")
33+
endpoint = input("Input endpoint (Without the starting slash): ")
3534
else:
3635
endpoint = input("Input endpoint (With the starting slash): ")
3736
request_url += endpoint
@@ -44,8 +43,7 @@ def get_request(cls):
4443
print(f"Reponse Status Code: {response.status_code}")
4544
response_data = json.loads(response.content)
4645
parsed_json = json.dumps(response_data, indent=4)
47-
output_json = highlight(parsed_json, lexers.JsonLexer(),
48-
formatters.TerminalFormatter())
46+
output_json = highlight(parsed_json, lexers.JsonLexer(), formatters.TerminalFormatter())
4947
print(output_json)
5048

5149
store_data = input('Store response data? (Y/N): ')
@@ -55,8 +53,7 @@ def get_request(cls):
5553
print("Response data stored in response_data.json")
5654

5755
except requests.exceptions.InvalidSchema:
58-
print("Check whether the URL is valid or check if \
59-
the localhost server is active or not")
56+
print("Check whether the URL is valid or check if the localhost server is active or not")
6057
except Exception as e:
6158
print(e)
6259

src/arguments/geckodriver.log

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/arguments/search.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ def prompt(self):
2020
print(colored(f"{self.message} : ", 'cyan'), end='')
2121
data = input()
2222
if data == "":
23-
SearchError("\U0001F613 Input data empty",
24-
"\U0001F504 Please try again ")
23+
SearchError("\U0001F613 Input data empty", "\U0001F504 Please try again ")
2524
sys.exit()
2625
else:
2726
return str(data)
@@ -75,17 +74,15 @@ def search_for_results(self, save=False):
7574
questions = self.utility_object.get_que(json_output)
7675
if questions == []:
7776
# evoke an error
78-
search_error = SearchError("\U0001F613 No answer found",
79-
"\U0001F604 Please try reddit")
77+
search_error = SearchError("\U0001F613 No answer found", "\U0001F604 Please try reddit")
8078
else:
8179
data = self.utility_object.get_ans(questions)
8280
print('''
8381
\U0001F604 Hopefully you found what you were looking for!
8482
\U0001F4C2 You can save an answer to a file with '-file'
8583
8684
Not found what you were looking for \U00002754
87-
\U0001F4C4 Open browser and post your question
88-
on StackOverflow with '-n [title (optional)]'
85+
\U0001F4C4 Open browser and post your question on StackOverflow with '-n [title (optional)]'
8986
9087
\U0001F50E To search more use '-s'
9188
''')

src/arguments/update.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,21 @@ def __init__(self, current_version):
1818
1919
"""
2020
self.current_version = current_version
21-
self.release_api_url = "https://api.github.com/repos/IndianOpen \
22-
SourceFoundation/dynamic-cli/releases/latest"
21+
self.release_api_url = "https://api.github.com/repos/IndianOpenSourceFoundation/dynamic-cli/releases/latest"
2322

2423
def check_for_updates(self):
2524
try:
2625
data = requests.get(self.release_api_url)
2726
data = data.json()
2827
if 'message' in data:
2928
if data['message'] == "Not Found":
30-
print(colored("The application do not have any release",
31-
"yellow"))
29+
print(colored("The application do not have any release", "yellow"))
3230
return None
3331

3432
if data["tag_name"] == self.current_version:
35-
print(colored("Yeah! You have the latest version",
36-
"green"))
33+
print(colored("Yeah! You have the latest version", "green"))
3734
else:
38-
print(colored(f"New release found - {data.tag_name}",
39-
"red"))
35+
print(colored(f"New release found - {data.tag_name}", "red"))
4036
webbrowser.open(data["html_url"])
4137

4238
except Exception as exception:

src/arguments/utility.py

Lines changed: 30 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ def __init__(self):
4343

4444
@property
4545
def playbook_path(self):
46-
"""
47-
Create an environment variable 'DYNAMIC'
48-
containing the path of dynamic_playbook.json and returns it
49-
"""
46+
# Create an environment variable 'DYNAMIC' containing the path of dynamic_playbook.json and returns it
5047
if not os.getenv(self.key):
5148
if(sys.platform=='linux'):
5249
os.environ[self.key] = os.path.join(self.linux_path, self.file_name)
@@ -137,28 +134,19 @@ def delete_from_playbook(self, stackoverflow_object, question_id):
137134
def display_panel(self):
138135
playbook_data = self.playbook_content
139136
if(len(playbook_data['items_stackoverflow']) == 0):
140-
SearchError("You have no entries in the playbook",
141-
"Browse and save entries in playbook with 'p' key")
137+
SearchError("You have no entries in the playbook", "Browse and save entries in playbook with 'p' key")
142138
sys.exit()
143-
# Creates QuestionPanelStackoverflow object
144-
# populates its question_data and answer_data and displays it
139+
# Creates QuestionPanelStackoverflow object, populates its question_data and answer_data and displays it
145140
question_panel = QuestionsPanelStackoverflow()
146141
for item in playbook_data['items_stackoverflow']:
147-
question_panel.questions_data.append( [item['question_title'],
148-
item['question_id'],
149-
item['question_link']] )
142+
question_panel.questions_data.append( [item['question_title'], item['question_id'], item['question_link']] )
150143
question_panel.answer_data[item['question_id']] = item['answer_body']
151144
question_panel.display_panel([], playbook=True)
152145

153146
class QuestionsPanelStackoverflow():
154147
def __init__(self):
155-
# list( list( question_title, question_id, question_link )... )
156-
self.questions_data = []
157-
158-
# dict( question_id:list( body, link ))
159-
# corresponding to self.questions_data
160-
self.answer_data = defaultdict(lambda: False)
161-
148+
self.questions_data = [] # list( list( question_title, question_id, question_link )... )
149+
self.answer_data = defaultdict(lambda: False) # dict( question_id:list( body, link )) corresponding to self.questions_data
162150
self.line_color = "bold red"
163151
self.heading_color = "bold blue"
164152
self.utility = Utility()
@@ -167,9 +155,8 @@ def __init__(self):
167155
def populate_question_data(self, questions_list):
168156
"""
169157
Function to populate question data property
170-
Creates batch request to stackexchange API and to get question
171-
details of questions with id in the list. Stores the returned
172-
data in the following format:
158+
Creates batch request to stackexchange API and to get question details of
159+
questions with id in the list. Stores the returned data data in the following format:
173160
list( list( question_title, question_link, question_id ) )
174161
"""
175162
with console.status("Getting the questions..."):
@@ -181,9 +168,7 @@ def populate_question_data(self, questions_list):
181168
SearchError("Search Failed", "Try connecting to the internet")
182169
sys.exit()
183170
json_ques_data = resp.json()
184-
self.questions_data = [[item['title'].replace('|',''),
185-
item['question_id'], item['link']]
186-
for item in json_ques_data["items"]]
171+
self.questions_data = [[item['title'].replace('|',''), item['question_id'], item['link']] for item in json_ques_data["items"]]
187172

188173
def populate_answer_data(self, questions_list):
189174
"""
@@ -204,19 +189,16 @@ def populate_answer_data(self, questions_list):
204189
for item in json_ans_data["items"]:
205190
if not(self.answer_data[item['question_id']]):
206191
self.answer_data[item['question_id']] = item['body_markdown']
207-
# Sometimes the StackExchange API fails to deliver some answers.
208-
# The below code is to fetch them
209-
failed_ques_id = [question[1] for question in self.questions_data
210-
if not(self.answer_data[question[1]])]
192+
# Sometimes the StackExchange API fails to deliver some answers. The below code is to fetch them
193+
failed_ques_id = [question[1] for question in self.questions_data if not(self.answer_data[question[1]])]
211194
if not(len(failed_ques_id) == 0):
212195
self.populate_answer_data(failed_ques_id)
213196

214197
def return_formatted_ans(self, ques_id):
215198
# This function uses uses Rich Markdown to format answers body.
216199
body_markdown = self.answer_data[int(ques_id)]
217200
body_markdown = str(body_markdown)
218-
xml_markup_replacement = [("&amp;", "&"), ("&lt;", "<"), ("&gt;", ">"),
219-
("&quot;", "\""), ("&apos;", "\'"), ("&#39;", "\'")]
201+
xml_markup_replacement = [("&amp;", "&"), ("&lt;", "<"), ("&gt;", ">"), ("&quot;", "\""), ("&apos;", "\'"), ("&#39;", "\'")]
220202
for convert_from, convert_to in xml_markup_replacement:
221203
body_markdown = body_markdown.replace(convert_from, convert_to)
222204
width = os.get_terminal_size().columns
@@ -225,32 +207,20 @@ def return_formatted_ans(self, ques_id):
225207
with console.capture() as capture:
226208
console.print(markdown)
227209
highlighted = capture.get()
228-
if not('UTF' in locale.getlocale()[1]):
229-
box_replacement = [("─", "-"), ("═","="), ("║","|"), ("│", "|"),
230-
('┌', '+'), ("└", "+"), ("┐", "+"), ("┘", "+"),
231-
("╔", "+"), ("╚", "+"), ("╗","+"), ("╝", "+"), ("•","*")]
210+
if locale.getlocale()[1] !='UTF-8':
211+
box_replacement = [("─", "-"), ("═","="), ("║","|"), ("│", "|"), ('┌', '+'), ("└", "+"), ("┐", "+"), ("┘", "+"), ("╔", "+"), ("╚", "+"), ("╗","+"), ("╝", "+"), ("•","*")]
232212
for convert_from, convert_to in box_replacement:
233213
highlighted = highlighted.replace(convert_from, convert_to)
234214
return highlighted
235215

236216
def navigate_questions_panel(self, playbook=False):
237217
# Code for navigating through the question panel
238-
if playbook:
239-
message = 'Playbook Questions'
240-
instructions = ". Press 'd' to delete from playbook"
241-
keys = ('enter', 'd')
242-
else:
243-
message = 'Relevant Questions'
244-
instructions = ". Press 'p' to save in playbook"
245-
keys = ('enter', 'p')
218+
(message, instructions, keys) = ('Playbook Questions', ". Press 'd' to delete from playbook", ('enter', 'd')) if(playbook) else ('Relevant Questions', ". Press 'p' to save in playbook", ('p', 'enter'))
246219
console.rule('[bold blue] {}'.format(message), style="bold red")
247-
console.print("[yellow] Use arrow keys to navigate. \
248-
'q' or 'Esc' to quit. 'Enter' to open in a browser" +
249-
instructions)
220+
console.print("[yellow] Use arrow keys to navigate. 'q' or 'Esc' to quit. 'Enter' to open in a browser" + instructions)
250221
console.print()
251222
options = ["|".join(map(str, question)) for question in self.questions_data]
252-
question_menu = TerminalMenu(options, preview_command=self.return_formatted_ans,
253-
preview_size=0.75, accept_keys=keys)
223+
question_menu = TerminalMenu(options, preview_command=self.return_formatted_ans, preview_size=0.75, accept_keys=keys)
254224
quitting = False
255225
while not(quitting):
256226
options_index = question_menu.show()
@@ -303,15 +273,10 @@ def get_batch_ans_url(self, ques_id_list):
303273

304274
def make_request(self, que, tag: str):
305275
"""
306-
This function uses the requests library to make
307-
the rest api call to the stackexchange server.
308-
:param que: The user questions that servers as
309-
a question in the api.
276+
This function uses the requests library to make the rest api call to the stackexchange server.
277+
:param que: The user questions that servers as a question in the api.
310278
:type que: String
311-
:param tag: The tags that user wants for searching the relevant
312-
answers. For e.g. TypeError might be for multiple
313-
languages so is tag is used as "Python" then the
314-
api will return answers based on the tags and question.
279+
:param tag: The tags that user wants for searching the relevant answers. For e.g. TypeError might be for multiple languages so is tag is used as "Python" then the api will return answers based on the tags and question.
315280
:type tag: String
316281
:return: Json response from the api call.
317282
:rtype: Json format data
@@ -320,8 +285,7 @@ def make_request(self, que, tag: str):
320285
try:
321286
resp = requests.get(self.__get_search_url(que, tag))
322287
except:
323-
SearchError("\U0001F613 Search Failed",
324-
"\U0001F4BB Try connecting to the internet")
288+
SearchError("\U0001F613 Search Failed", "\U0001F4BB Try connecting to the internet")
325289
sys.exit()
326290
return resp.json()
327291

@@ -350,23 +314,19 @@ def get_ans(self, questions_list):
350314
@classmethod
351315
def setCustomKey(self):
352316
client_id = 20013
353-
"""
354-
scopes possible values:
355-
read_inbox - access a user's global inbox
356-
no_expiry - access_token's with this scope do not expire
357-
write_access - perform write operations as a user
358-
private_info - access full history of a user's private
359-
actions on the site
360-
"""
317+
318+
# scopes possible values:
319+
# read_inbox - access a user's global inbox
320+
# no_expiry - access_token's with this scope do not expire
321+
# write_access - perform write operations as a user
322+
# private_info - access full history of a user's private actions on the site
361323
scopes = 'read_inbox'
362324

363325
authorization_url = 'https://stackoverflow.com/oauth/dialog'
364326
redirect_uri = 'https://stackexchange.com/oauth/login_success'
365327

366-
# Create an OAuth session and open the auth_url in a browser
367-
# for the user to authenticate
368-
stackApps = OAuth2Session(client=MobileApplicationClient(client_id=client_id),
369-
scope=scopes, redirect_uri=redirect_uri)
328+
# Create an OAuth session and open the auth_url in a browser for the user to authenticate
329+
stackApps = OAuth2Session(client=MobileApplicationClient(client_id=client_id), scope=scopes, redirect_uri=redirect_uri)
370330
auth_url, state = stackApps.authorization_url(authorization_url)
371331

372332
# Try to install web drivers for one of these browsers
@@ -380,8 +340,7 @@ def setCustomKey(self):
380340
try:
381341
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
382342
except ValueError:
383-
print("You do not have one of these supported browsers: \
384-
Chrome, Firefox, Edge")
343+
print("You do not have one of these supported browsers: Chrome, Firefox, Edge")
385344

386345
# Open auth_url in one of the supported browsers
387346
driver.get(auth_url)

0 commit comments

Comments
 (0)