Skip to content

Commit

Permalink
Merge pull request #119 from KingAkeem/refactoring
Browse files Browse the repository at this point in the history
Refactoring & bug fixes
  • Loading branch information
PSNAppz authored Sep 15, 2018
2 parents 17b9902 + 551192f commit 0fe0d58
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 273 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ Contributor name will be updated to the below list. :D

### Python Dependencies
- beautifulsoup4
- pyinstaller
- PySocks
- termcolor
- requests
- python-dotenv
- tldextract
- requests_mock
- yattag

Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ go get golang.org/x/net/html
mkdir -p tmp_build
mkdir -p tmp_dist

pip install pyinstaller

# Creates executable file and sends dependences to the recently created directories
pyinstaller --onefile --workpath ./tmp_build --distpath ./tmp_dist torBot.py

Expand Down
14 changes: 0 additions & 14 deletions modules/bcolors.py

This file was deleted.

52 changes: 52 additions & 0 deletions modules/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

"""
Module containing class with colors
"""

class Colors:
"""
Class that contains colors used for TorBot in terminal and a method
that adds colr to a string
Attributes:
_colors (dict): A map containing all of the color codes needed
"""
def __init__(self):
self._colors = {
'white': "\033[1;37m",
'yellow': "\033[1;33m",
'green': "\033[1;32m",
'blue': "\033[1;34m",
'cyan': "\033[1;36m",
'red': "\033[1;31m",
'magenta': "\033[1;35m",
'black': "\033[1;30m",
'darkwhite': "\033[0;37m",
'darkyellow': "\033[0;33m",
'darkgreen': "\033[0;32m",
'darkblue': "\033[0;34m",
'darkcyan': "\033[0;36m",
'darkred': "\033[0;31m",
'darkmagenta':"\033[0;35m",
'darkblack': "\033[0;30m",
'end': "\033[0;0m"
}

def add(self, string, color):
"""
Method that adds color to a given string
Args:
string (str): string to add color to
color (str): string of color to add
"""
return self.get(color) + string + self.get('end')

def get(self, color):
"""
Method that returns the color code of the given color string
Args:
color (str): color code to be returned
"""
return self._colors[color]
22 changes: 13 additions & 9 deletions modules/getemails.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from modules.bcolors import Bcolors
from modules.net_utils import get_urls_from_page

"""
Module returns emails found on webpage
"""
from bs4 import BeautifulSoup

import modules.getweblinks
from modules.colors import Colors

COLOR = Colors()

def getMails(soup):
def get_mails(soup):
"""
Searches for <a href> tags for links then checks if link contains the
substring 'mailto' indicating that it's an email. If it is determined
Expand All @@ -16,18 +22,16 @@ def getMails(soup):
Returns:
emails: list of email IDs
"""
b_colors = Bcolors()

if isinstance(type(soup), type(BeautifulSoup)):

emails = get_urls_from_page(soup, email=True)
emails = modules.getweblinks.get_urls_from_page(soup, email=True)

# Pretty print output as below
print('')
print(b_colors.OKGREEN+'Mails Found - '+b_colors.ENDC+str(len(emails)))
success_string = 'Mails Found - ' + str(len(emails))
print(COLOR.add(success_string, 'green'))
print('-------------------------------')

return emails

else:
raise ValueError('Method parameter is not of instance BeautifulSoup')
raise ValueError('Method parameter is not of instance BeautifulSoup')
Loading

0 comments on commit 0fe0d58

Please sign in to comment.