Skip to content

Commit

Permalink
Pep8 code and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingAkeem committed Jan 6, 2018
1 parent f88f5af commit 9c972be
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 58 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
modules/__pycache__/
.*.swp
.ropeproject/
modules/.ropeproject/
tests/__pycache__/
modules/__init__.py
.idea/
tests/.ropeproject/
11 changes: 6 additions & 5 deletions modules/getemails.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from .bcolors import Bcolors
from modules.bcolors import Bcolors
from bs4 import BeautifulSoup
from .savefile import saveJson
from modules.savefile import saveJson


"""Get all emails from the website"""


def getMails(soup, save=0):
b_colors = Bcolors()
_soup_instance = BeautifulSoup
if isinstance(type(soup), type(_soup_instance)):
emails = []
Expand All @@ -21,15 +22,15 @@ def getMails(soup, save=0):
pass
"""Pretty print output as below"""
print ('')
print (Bcolors.OKGREEN+'Mails Found - '+Bcolors.ENDC+str(len(emails)))
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 ''
else:
msg = ''.join((Bcolors.FAIL,
msg = ''.join((b_colors.FAIL,
'Method parameter is not of instance BeautifulSoup',
Bcolors.ENDC))
b_colors.ENDC))
raise(msg)
7 changes: 4 additions & 3 deletions modules/getweblinks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import urllib.request
from .bcolors import Bcolors
from modules.bcolors import Bcolors
from bs4 import BeautifulSoup



def link_status(web, out_queue, index):
b_colors = Bcolors()
out_queue[index] = web + " is_live = False "
Expand All @@ -29,18 +30,18 @@ def getLinks(soup, ext, live=0, save=0):

for link in soup.find_all('a'):
web_link = link.get('href')
if 'http' in web_link or 'https' in web_link:
if web_link and ('http' in web_link or 'https' in web_link):

for exten in extensions:
if web_link.endswith(exten):
websites.append(web_link)
else:
websites.append(web_link)
print(websites)
"""Pretty print output as below"""
print(''.join((b_colors.OKGREEN,
'Websites Found - ', b_colors.ENDC, str(len(websites)))))
print('-------------------------------')
return websites

else:
raise('Method parameter is not of instance BeautifulSoup')
2 changes: 1 addition & 1 deletion modules/pagereader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import urllib.request
from bs4 import BeautifulSoup
from .bcolors import Bcolors
from modules.bcolors import Bcolors


def readPage(site, printIP=0):
Expand Down
38 changes: 24 additions & 14 deletions tests/test_getemails.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import sys
import os
import unittest

PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(
os.path.join(os.getcwd(), os.path.expanduser(__file__))))

sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

from modules import pagereader, getemails
from io import StringIO
sys.path.append(os.path.abspath('../modules'))
import getemails
from bcolors import Bcolors
import pagereader
from modules.bcolors import Bcolors


soup = pagereader.readPage('http://www.whatsmyip.net/')


class getMailsTestCase(unittest.TestCase):

def setUp(self):
self.held, sys.stdout = sys.stdout, StringIO()

def test_print_emails(self):
data = "\n"+Bcolors.OKGREEN+"Mails Found - "+Bcolors.ENDC+"1\n-------------------------------\n[email protected]\n"
getemails.getMails(soup)
self.assertEqual(sys.stdout.getvalue(),data)


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)


if __name__ == '__main__':
unittest.main()
unittest.main()
46 changes: 29 additions & 17 deletions tests/test_getweblinks.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
#!/usr/bin/env python

import unittest
import sys
import os
import unittest
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(
os.path.join(os.getcwd(), os.path.expanduser(__file__))))

sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
from io import StringIO
sys.path.append(os.path.abspath('../modules'))
import getweblinks
from bcolors import Bcolors
import pagereader
from modules.bcolors import Bcolors
from modules import getweblinks, pagereader

soup = pagereader.readPage('http://www.whatsmyip.net/')


class getLinksTestCase(unittest.TestCase):

def setUp(self):
self.held, sys.stdout = sys.stdout, StringIO()
self.maxDiff=None

def test_print_links(self):
#data = "\nWebsites Found - 7\n-------------------------------\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIP856a6b4\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIPbf5d683\nhttp://aff.ironsocket.com/SH7L\nhttp://aff.ironsocket.com/SH7L\nhttp://ads.wsrs.net/www/delivery/ck.php?n=MyIPdb5f512\nhttp://wsrs.net/\nhttp://cmsgear.com/\n"
data = "\n"+Bcolors.OKGREEN+"Websites Found - "+Bcolors.ENDC+"1\n-------------------------------\nhttp://cmsgear.com/\n"
ext = ['.com/']
getweblinks.getLinks(soup,ext)
self.assertEqual(sys.stdout.getvalue(),data)

def setUp(self):
self.b_colors = Bcolors()
self.held, sys.stdout = sys.stdout, StringIO()
self.maxDiff = None

def test_print_links(self):

data = ['http://aff.ironsocket.com/SH7L',
'http://aff.ironsocket.com/SH7L',
'http://wsrs.net/',
'http://cmsgear.com/',
'http://cmsgear.com/']

ext = ['.com/']
result = getweblinks.getLinks(soup, ext)
self.assertEqual(result, data)


if __name__ == '__main__':
unittest.main()
unittest.main()
43 changes: 26 additions & 17 deletions tests/test_savetofile.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
import sys
import os
import unittest
from io import StringIO
sys.path.append(os.path.abspath('../modules'))
import getweblinks
from bcolors import Bcolors
import pagereader
import time
PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(
os.path.join(os.getcwd(), os.path.expanduser(__file__))))

sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

from io import StringIO
from modules.bcolors import Bcolors
from modules import getweblinks, pagereader

soup = pagereader.readPage('http://www.whatsmyip.net/')
timestr = time.strftime("%Y%m%d-%H%M%S")


class getLinksTestCase(unittest.TestCase):

def setUp(self):
self.held, sys.stdout = sys.stdout, StringIO()
self.maxDiff=None

def test_save_links(self):
data = "\n"+Bcolors.OKGREEN+"Websites Found - "+Bcolors.ENDC+"1\n-------------------------------\nhttp://cmsgear.com/\n\nData will be saved with a File Name :"+ "TorBoT-Export-Onion-Links"+timestr+".json\n"
ext = ['.com/']
getweblinks.getLinks(soup,ext,0,1)
self.assertEqual(sys.stdout.getvalue(),data)

def setUp(self):
self.held, sys.stdout = sys.stdout, StringIO()
self.maxDiff = None
self.b_colors = Bcolors()

if __name__ == '__main__':
unittest.main()
def test_save_links(self):
data = ['http://aff.ironsocket.com/SH7L',
'http://aff.ironsocket.com/SH7L',
'http://wsrs.net/',
'http://cmsgear.com/',
'http://cmsgear.com/']
ext = ['.com/']
result = getweblinks.getLinks(soup, ext, 0, 1)
self.assertEqual(result, data)


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion torBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def main():
info.executeAll(link)

if b is not None:
getweblinks.getLinks(b, ext, live, save)
links = getweblinks.getLinks(b, ext, live, save)
print(links)

print("\n\n")

Expand Down

1 comment on commit 9c972be

@agrepravin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work KingAkeem

Please sign in to comment.