Skip to content

Commit

Permalink
PEP8 Styling Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenOSanders committed Jul 31, 2019
1 parent 6f5e336 commit 7cdeb4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
7 changes: 5 additions & 2 deletions autostack/features/query_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
print_accepted_post
)


def custom_query():
'''
Searches Stack Overflow using a custom search query from the user.
Expand All @@ -28,8 +29,10 @@ def custom_query():
# Display Stack Overflow posts for the error.
print_accepted_post(post)

# If the user's question has been answered,
# don't keep looping over posts.
'''
If the user's question has been answered,
don't keep looping over posts.
'''
while True:
print('Did this answer your question? (Y/n): ', end='')
question_answered = input()
Expand Down
23 changes: 16 additions & 7 deletions autostack/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ def main():

# Variable to count number of "no"s.
no_counter = 0

# If the current line of output is a python error,
# query Stack Overflow.
'''
If the current line of output is a python error,
query Stack Overflow.
'''
if output.split()[0][:-1] in EXCEPTIONS:
for post in accepted_posts(output):
# Display Stack Overflow posts for the error.
print_accepted_post(post)

# If the user's question has been answered,
# don't keep looping over posts.
'''
If the user's question has been answered,
don't keep looping over posts.
'''
while True:
print('Did this answer your question? (Y/n): ', end='')
question_answered = input()
Expand All @@ -107,10 +110,16 @@ def main():
break
elif question_answered == 'n':
no_counter += 1
# If three "no"s occur in a row let the user enter a custom query.
'''
If three "no"s occur in a row
let the user enter a custom query.
'''
if(no_counter == 3):
no_counter = 0
custom_query()
# After user finds an answer from their query, break loop to listen for more errors.
'''
After user finds an answer from their query,
break loop to listen for more errors.
'''
break
continue
10 changes: 5 additions & 5 deletions autostack/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

def test_main_pipe_dir_doesnt_exist():
'''
Test to ensure that the pipe is created even if the
Test to ensure that the pipe is created even if the
pipe dir doesn't exist.
'''

# 1. Given.
try:
os.system('rm -rf /tmp/')
except:
except:
assert True

# 2. When.
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_main_pipe_doesnt_exist():

def test_main_input_y():
'''
Test to ensure that, when an error is detected, inputting
Test to ensure that, when an error is detected, inputting
'Y' exits the post query loop.
'''

Expand All @@ -77,7 +77,7 @@ def test_main_input_y():

def test_main_input_n():
'''
Test to ensure that, when an error is detected, inputting
Test to ensure that, when an error is detected, inputting
'n' continues the post query loop.
'''

Expand All @@ -87,4 +87,4 @@ def test_main_input_n():

# 3. Then.

pass
pass
10 changes: 4 additions & 6 deletions autostack/web_scraper/stack_overflow_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def accepted_posts(query):
# The 'soup' of the query page.
request = requests.get(query_url)

# Erros ordered from specific to general so the specific ones don't get masked by the general ones.
'''
Errors ordered from specific to general so the
specific ones don't get masked by the general ones.
'''
try:
# Raise exception or error if it exists.
request.raise_for_status()
Expand All @@ -58,11 +61,6 @@ def accepted_posts(query):
except requests.exceptions.SSLError as errs:
print ('SSL Error:',errs)
return None
# except requests.exceptions.Timeout as errt:
# Catching this error catches both Connection and Read Timeout
# # Maybe set up for a retry, or continue in a retry loop
# print ('Timeout Error:',errt)
# return None
except requests.exceptions.ConnectTimeout as errct:
print ('Connection Timeout:',errct)
return None
Expand Down

0 comments on commit 7cdeb4b

Please sign in to comment.