-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from KingAkeem/dev
Beautiful and comprehensible code base. (Documenting and Refactoring)
- Loading branch information
Showing
9 changed files
with
218 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
from modules.bcolors import Bcolors | ||
from bs4 import BeautifulSoup | ||
from modules.savefile import saveJson | ||
|
||
|
||
"""Get all emails from the website""" | ||
def getMails(soup): | ||
|
||
""" | ||
Searches for <a href> tags for links then checks if link ccontains the | ||
substring 'mailto' indicating that it's an email. If it is determined | ||
to be an email then the link is split and the username is appeneded to | ||
the list | ||
def getMails(soup, save=0): | ||
Args: | ||
soup: BeautifulSoup isntance that will be used for parsing | ||
Returns: | ||
emails: list of email IDs | ||
""" | ||
b_colors = Bcolors() | ||
_soup_instance = BeautifulSoup | ||
if isinstance(type(soup), type(_soup_instance)): | ||
|
||
if isinstance(type(soup), type(BeautifulSoup)): | ||
|
||
emails = [] | ||
for link in soup.find_all('a'): | ||
email_link = link.get('href') | ||
if email_link is not None: | ||
if 'mailto' in email_link: | ||
"""Split email address on""" | ||
email_addr = email_link.split(':') | ||
emails.append(email_addr[1]) | ||
else: | ||
pass | ||
links = soup.find_all('a') | ||
for ref in links: | ||
url = ref.get('href') | ||
if url and 'mailto' in url: | ||
"""Split email address on""" | ||
email_addr = url.split(':') | ||
emails.append(email_addr[1]) | ||
|
||
"""Pretty print output as below""" | ||
print ('') | ||
print (b_colors.OKGREEN+'Mails Found - '+b_colors.ENDC+str(len(emails))) | ||
print ('-------------------------------') | ||
for mail in emails: | ||
print (mail) | ||
if save: | ||
saveJson("Extracted-Mail-IDs", emails) | ||
return '' | ||
|
||
return emails | ||
|
||
else: | ||
msg = ''.join((b_colors.FAIL, | ||
'Method parameter is not of instance BeautifulSoup', | ||
b_colors.ENDC)) | ||
raise(msg) | ||
raise('Method parameter is not of instance BeautifulSoup') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) | ||
|
||
from modules import pagereader, getemails | ||
from io import StringIO | ||
from modules.bcolors import Bcolors | ||
|
||
|
||
|
@@ -19,15 +18,12 @@ | |
class getMailsTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.held, sys.stdout = sys.stdout, StringIO() | ||
self.b_colors = Bcolors() | ||
|
||
def test_print_emails(self): | ||
data = ''.join(("\n", self.b_colors.OKGREEN, "Mails Found - ", | ||
self.b_colors.ENDC, "1\n------------------------", | ||
"-------\n[email protected]\n")) | ||
getemails.getMails(soup) | ||
self.assertEqual(sys.stdout.getvalue(), data) | ||
def test_getemails(self): | ||
test_emails = ["[email protected]"] | ||
emails = getemails.getMails(soup) | ||
self.assertEqual(emails, test_emails) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.