Skip to content

Commit

Permalink
Merge pull request #25 from autostack-team/develop
Browse files Browse the repository at this point in the history
Finished so_web_scraper refactoring
  • Loading branch information
elijahsawyers authored Oct 22, 2019
2 parents 5a0eccb + 41d21de commit 34d539c
Showing 1 changed file with 24 additions and 35 deletions.
59 changes: 24 additions & 35 deletions autostack/so_web_scraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,43 +147,11 @@ def print_accepted_post(post):
to print.
'''

question = None
try:
question = post.find(
attrs={
'class',
'question'
}
).find(
attrs={
'class',
'post-text'
}
)
except AttributeError:
return
finally:
if not question:
return
question = get_post_text(post, 'question')
accepted_answer = get_post_text(post, 'accepted-answer')

accepted_answer = None
try:
accepted_answer = post.find(
attrs={
'class',
'accepted-answer'
}
).find(
attrs={
'class',
'post-text'
}
)
except AttributeError:
if question is None or accepted_answer is None:
return
finally:
if not accepted_answer:
return

print(colored('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', 'red'))
print(colored('Question:', 'red'))
Expand All @@ -200,6 +168,27 @@ def print_accepted_post(post):
print(colored('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~', 'red'))


def get_post_text(post, html_class):
'''
TODO: Write docstring.
'''

try:
return post.find(
attrs={
'class',
html_class
}
).find(
attrs={
'class',
'post-text'
}
)
except AttributeError:
return None


def print_post_text(post_text):
'''
Prints post-text from Stack Overflow.
Expand Down

0 comments on commit 34d539c

Please sign in to comment.