Skip to content

Commit 2005aaa

Browse files
committed
Change code style to PEP8
1 parent 70f199b commit 2005aaa

File tree

5 files changed

+99
-40
lines changed

5 files changed

+99
-40
lines changed

src/arguments/api_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ 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 (Without the starting slash): ")
33+
endpoint = input("Input endpoint \
34+
(Without the starting slash): ")
3435
else:
3536
endpoint = input("Input endpoint (With the starting slash): ")
3637
request_url += endpoint
@@ -43,7 +44,8 @@ def get_request(cls):
4344
print(f"Reponse Status Code: {response.status_code}")
4445
response_data = json.loads(response.content)
4546
parsed_json = json.dumps(response_data, indent=4)
46-
output_json = highlight(parsed_json, lexers.JsonLexer(), formatters.TerminalFormatter())
47+
output_json = highlight(parsed_json, lexers.JsonLexer(),
48+
formatters.TerminalFormatter())
4749
print(output_json)
4850

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

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

src/arguments/geckodriver.log

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1620819173118 geckodriver INFO Listening on 127.0.0.1:43595
2+
1620819174128 mozrunner::runner INFO Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileJyNk0h"
3+
1620819175328 Marionette INFO Marionette enabled
4+
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new Error("", "(unknown module)"))
5+
1620819177989 Marionette INFO Listening on port 42369
6+
1620819178065 Marionette WARN TLS certificate errors will be ignored for this session
7+
JavaScript error: resource://gre/actors/AutoCompleteChild.jsm, line 125: Error: Invalid autocomplete selectedIndex
8+
1620819180695 Marionette INFO Stopped listening on port 42369

src/arguments/search.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def prompt(self):
2020
print(colored(f"{self.message} : ", 'cyan'), end='')
2121
data = input()
2222
if data == "":
23-
SearchError("\U0001F613 Input data empty", "\U0001F504 Please try again ")
23+
SearchError("\U0001F613 Input data empty",
24+
"\U0001F504 Please try again ")
2425
sys.exit()
2526
else:
2627
return str(data)
@@ -74,15 +75,17 @@ def search_for_results(self, save=False):
7475
questions = self.utility_object.get_que(json_output)
7576
if questions == []:
7677
# evoke an error
77-
search_error = SearchError("\U0001F613 No answer found", "\U0001F604 Please try reddit")
78+
search_error = SearchError("\U0001F613 No answer found",
79+
"\U0001F604 Please try reddit")
7880
else:
7981
data = self.utility_object.get_ans(questions)
8082
print('''
8183
\U0001F604 Hopefully you found what you were looking for!
8284
\U0001F4C2 You can save an answer to a file with '-file'
8385
8486
Not found what you were looking for \U00002754
85-
\U0001F4C4 Open browser and post your question on StackOverflow with '-n [title (optional)]'
87+
\U0001F4C4 Open browser and post your question
88+
on StackOverflow with '-n [title (optional)]'
8689
8790
\U0001F50E To search more use '-s'
8891
''')

src/arguments/update.py

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

2324
def check_for_updates(self):
2425
try:
2526
data = requests.get(self.release_api_url)
2627
data = data.json()
2728
if 'message' in data:
2829
if data['message'] == "Not Found":
29-
print(colored("The application do not have any release", "yellow"))
30+
print(colored("The application do not have any release",
31+
"yellow"))
3032
return None
3133

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

3842
except Exception as exception:

src/arguments/utility.py

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

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

146153
class QuestionsPanelStackoverflow():
147154
def __init__(self):
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
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+
150162
self.line_color = "bold red"
151163
self.heading_color = "bold blue"
152164
self.utility = Utility()
@@ -155,8 +167,9 @@ def __init__(self):
155167
def populate_question_data(self, questions_list):
156168
"""
157169
Function to populate question data property
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:
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:
160173
list( list( question_title, question_link, question_id ) )
161174
"""
162175
with console.status("Getting the questions..."):
@@ -168,7 +181,9 @@ def populate_question_data(self, questions_list):
168181
SearchError("Search Failed", "Try connecting to the internet")
169182
sys.exit()
170183
json_ques_data = resp.json()
171-
self.questions_data = [[item['title'].replace('|',''), item['question_id'], item['link']] for item in json_ques_data["items"]]
184+
self.questions_data = [[item['title'].replace('|',''),
185+
item['question_id'], item['link']]
186+
for item in json_ques_data["items"]]
172187

173188
def populate_answer_data(self, questions_list):
174189
"""
@@ -189,16 +204,19 @@ def populate_answer_data(self, questions_list):
189204
for item in json_ans_data["items"]:
190205
if not(self.answer_data[item['question_id']]):
191206
self.answer_data[item['question_id']] = item['body_markdown']
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]])]
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]])]
194211
if not(len(failed_ques_id) == 0):
195212
self.populate_answer_data(failed_ques_id)
196213

197214
def return_formatted_ans(self, ques_id):
198215
# This function uses uses Rich Markdown to format answers body.
199216
body_markdown = self.answer_data[int(ques_id)]
200217
body_markdown = str(body_markdown)
201-
xml_markup_replacement = [("&amp;", "&"), ("&lt;", "<"), ("&gt;", ">"), ("&quot;", "\""), ("&apos;", "\'"), ("&#39;", "\'")]
218+
xml_markup_replacement = [("&amp;", "&"), ("&lt;", "<"), ("&gt;", ">"),
219+
("&quot;", "\""), ("&apos;", "\'"), ("&#39;", "\'")]
202220
for convert_from, convert_to in xml_markup_replacement:
203221
body_markdown = body_markdown.replace(convert_from, convert_to)
204222
width = os.get_terminal_size().columns
@@ -207,20 +225,32 @@ def return_formatted_ans(self, ques_id):
207225
with console.capture() as capture:
208226
console.print(markdown)
209227
highlighted = capture.get()
210-
if locale.getlocale()[1] !='UTF-8':
211-
box_replacement = [("─", "-"), ("═","="), ("║","|"), ("│", "|"), ('┌', '+'), ("└", "+"), ("┐", "+"), ("┘", "+"), ("╔", "+"), ("╚", "+"), ("╗","+"), ("╝", "+"), ("•","*")]
228+
if not('UTF' in locale.getlocale()[1]):
229+
box_replacement = [("─", "-"), ("═","="), ("║","|"), ("│", "|"),
230+
('┌', '+'), ("└", "+"), ("┐", "+"), ("┘", "+"),
231+
("╔", "+"), ("╚", "+"), ("╗","+"), ("╝", "+"), ("•","*")]
212232
for convert_from, convert_to in box_replacement:
213233
highlighted = highlighted.replace(convert_from, convert_to)
214234
return highlighted
215235

216236
def navigate_questions_panel(self, playbook=False):
217237
# Code for navigating through the question panel
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'))
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')
219246
console.rule('[bold blue] {}'.format(message), style="bold red")
220-
console.print("[yellow] Use arrow keys to navigate. 'q' or 'Esc' to quit. 'Enter' to open in a browser" + instructions)
247+
console.print("[yellow] Use arrow keys to navigate. \
248+
'q' or 'Esc' to quit. 'Enter' to open in a browser" +
249+
instructions)
221250
console.print()
222251
options = ["|".join(map(str, question)) for question in self.questions_data]
223-
question_menu = TerminalMenu(options, preview_command=self.return_formatted_ans, preview_size=0.75, accept_keys=keys)
252+
question_menu = TerminalMenu(options, preview_command=self.return_formatted_ans,
253+
preview_size=0.75, accept_keys=keys)
224254
quitting = False
225255
while not(quitting):
226256
options_index = question_menu.show()
@@ -273,10 +303,15 @@ def get_batch_ans_url(self, ques_id_list):
273303

274304
def make_request(self, que, tag: str):
275305
"""
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.
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.
278310
:type que: String
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.
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.
280315
:type tag: String
281316
:return: Json response from the api call.
282317
:rtype: Json format data
@@ -285,7 +320,8 @@ def make_request(self, que, tag: str):
285320
try:
286321
resp = requests.get(self.__get_search_url(que, tag))
287322
except:
288-
SearchError("\U0001F613 Search Failed", "\U0001F4BB Try connecting to the internet")
323+
SearchError("\U0001F613 Search Failed",
324+
"\U0001F4BB Try connecting to the internet")
289325
sys.exit()
290326
return resp.json()
291327

@@ -314,19 +350,23 @@ def get_ans(self, questions_list):
314350
@classmethod
315351
def setCustomKey(self):
316352
client_id = 20013
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
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+
"""
323361
scopes = 'read_inbox'
324362

325363
authorization_url = 'https://stackoverflow.com/oauth/dialog'
326364
redirect_uri = 'https://stackexchange.com/oauth/login_success'
327365

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)
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)
330370
auth_url, state = stackApps.authorization_url(authorization_url)
331371

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

345386
# Open auth_url in one of the supported browsers
346387
driver.get(auth_url)

0 commit comments

Comments
 (0)