Skip to content

Commit

Permalink
Py3UpgradePEP8
Browse files Browse the repository at this point in the history
Signed-off-by: MikeMeliz <[email protected]>
  • Loading branch information
MikeMeliz committed Aug 2, 2020
1 parent 07c02e8 commit 882a9af
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
47 changes: 24 additions & 23 deletions modules/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,50 @@
import re
import subprocess
import os
from urllib2 import urlopen
from urllib.request import urlopen
from json import load
from urllib.parse import urlparse


# Parser of URL
def urlcanon(website, verbose):
if not website.startswith("http"):
if not website.startswith("www."):
website = "www." + website
if verbose:
print("## URL fixed: " + website)
print(("## URL fixed: " + website))
website = "http://" + website
if verbose:
print("## URL fixed: " + website)
print(("## URL fixed: " + website))
return website


def extract_domain(url, remove_http=True):
uri = urlparse(url)
if remove_http:
domain_name = f"{uri.netloc}"
else:
domain_name = f"{uri.netloc}://{uri.netloc}"
return domain_name


# Create output path
def folder(website, verbose):
if website.startswith('http'):
outpath = website.replace("http://", "")
if website.startswith('https'):
outpath = website.replace("https://", "")
else:
outpath = website
if outpath.endswith('/'):
outpath = outpath[:-1]
outpath = website
if not os.path.exists(outpath):
os.makedirs(outpath)
if verbose:
print("## Folder created: " + outpath)
print(("## Folder created: " + outpath))
return outpath


# Check if TOR service is running
def checkTor(verbose):
checkTor = subprocess.check_output(['ps', '-e'])
def checktor(verbose):
checkfortor = subprocess.check_output(['ps', '-e'])

def findWholeWord(w):
def findwholeword(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search

if findWholeWord('tor')(checkTor):
if findwholeword('tor')(checkfortor):
if verbose:
print("## TOR is ready!")
else:
Expand All @@ -55,12 +57,11 @@ def findWholeWord(w):


# Check your IP from external website
def checkIP():
def checkip():
try:
global webIPcheck
webIPcheck = 'https://api.ipify.org/?format=json'
my_ip = load(urlopen(webIPcheck))['ip']
print '## Your IP: ' + my_ip
webipcheck = 'https://api.ipify.org/?format=json'
my_ip = load(urlopen(webipcheck))['ip']
print(('## Your IP: ' + my_ip))
except:
e = sys.exc_info()[0]
print("Error: %s" % e + "\n## IP can't obtain \n## Is " + webIPcheck + "up?")
print(("Error: %s" % e + "\n## IP can't obtain \n## Is " + webipcheck + "up?"))
28 changes: 14 additions & 14 deletions modules/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import sys
import urllib2
import urllib.request, urllib.parse, urllib.error


# Input links from file and extract them into path/files
Expand All @@ -13,7 +13,7 @@ def cinex(inputFile, outpath):
# print f
except IOError:
e = sys.exc_info()[0]
print("Error: %s" % e + "\n## Can't open " + inputFile)
print(("Error: %s" % e + "\n## Can't open " + inputFile))

for line in f:

Expand All @@ -29,23 +29,23 @@ def cinex(inputFile, outpath):
# Extract page to file
try:
f = open(outpath + "/" + outputFile, 'w')
f.write(urllib2.urlopen(line).read())
f.write(urllib.request.urlopen(line).read())
f.close()
print("## File created on " + os.getcwd() + "/" + outpath + "/" + outputFile)
print(("## File created on " + os.getcwd() + "/" + outpath + "/" + outputFile))
except:
e = sys.exc_info()[0]
print("Error: %s" % e + "\n Can't write on file " + outputFile)
print(("Error: %s" % e + "\n Can't write on file " + outputFile))


# Input links from file and extract them into terminal
def intermex(inputFile):
try:
f = open(inputFile, 'r')
for line in f:
print urllib2.urlopen(line).read()
print((urllib.request.urlopen(line).read()))
except:
e = sys.exc_info()[0]
print("Error: %s" % e + "\n## Not valid file")
print(("Error: %s" % e + "\n## Not valid file"))


# Output webpage into a file
Expand All @@ -54,20 +54,20 @@ def outex(website, outputFile, outpath):
try:
outputFile = outpath + "/" + outputFile
f = open(outputFile, 'w')
f.write(urllib2.urlopen(website).read())
f.write(urllib.request.urlopen(website).read())
f.close()
print("## File created on " + os.getcwd() + "/" + outputFile)
print(("## File created on " + os.getcwd() + "/" + outputFile))
except:
e = sys.exc_info()[0]
print("Error: %s" % e + "\n Can't write on file " + outputFile)
print(("Error: %s" % e + "\n Can't write on file " + outputFile))


# Output webpage into terminal
# Output to terminal
def termex(website):
try:
print urllib2.urlopen(website).read()
except (urllib2.HTTPError, urllib2.URLError) as e:
print("Error: (%s) %s" % (e, website))
print((urllib.request.urlopen(website).read()))
except (urllib.error.HTTPError, urllib.error.URLError) as e:
print(("Error: (%s) %s" % (e, website)))
return None


Expand Down

0 comments on commit 882a9af

Please sign in to comment.