Skip to content

Commit 402a369

Browse files
Small tweak
1 parent c5f6699 commit 402a369

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

inputHelper.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,30 @@ def getFilePath(user_arguments):
77
return 0
88

99

10+
def getHelp(user_arugments):
11+
helpFlag = "-h"
12+
helpFlagv2 = "--help"
13+
for arg in user_arugments:
14+
if arg == helpFlag or arg == helpFlagv2:
15+
return True
16+
return False
17+
18+
19+
def printHelp():
20+
print('-f <path_output_file>\tspesifiy the file you want filtered\n')
21+
print('-hm method1,method2,method3...\tfilters on HTTP methods (GET, POST etc.)\n')
22+
print('-c code1,code2,code3...\tfilters on HTTP Reponse code (200,404,301 etc.)\n')
23+
print('-h or --help prints this message\n')
24+
25+
1026
def getHttpMethods(user_arguments):
1127
amountOfArgs = len(user_arguments)
12-
httpFlag = "-h"
28+
httpFlag = "-hm"
1329
for i in range(amountOfArgs):
1430
if user_arguments[i] == httpFlag:
1531
arr = user_arguments[i + 1].split(",")
1632
return arr
17-
return 0
33+
return False
1834

1935

2036
def getResponseCodes(user_arguments):
@@ -24,4 +40,4 @@ def getResponseCodes(user_arguments):
2440
if user_arguments[i] == responseCodeFlag:
2541
arr = user_arguments[i + 1].split(",")
2642
return arr
27-
return 0
43+
return False

main.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import re
22
import sys
33

4-
from inputHelper import getFilePath, getHttpMethods, getResponseCodes
4+
from inputHelper import getFilePath, getHttpMethods, getResponseCodes, getHelp, printHelp
55
from regexHelper import buildResponseCodeRegex, buildHttpMethodRegex
66

7+
if getHelp(sys.argv):
8+
printHelp()
9+
quit(1)
710
pathToFile = getFilePath(sys.argv)
811
httpMethods = getHttpMethods(sys.argv)
912
responseCodes = getResponseCodes(sys.argv)
13+
httpMethodReg = ""
14+
responseCodeReg = ""
15+
16+
if not pathToFile:
17+
print("no file path, use -f to specify a path file")
18+
quit(1)
19+
if httpMethods:
20+
httpMethodReg = buildHttpMethodRegex(httpMethods)
21+
file = open(pathToFile, "r")
22+
for line in file:
23+
if re.findall(httpMethodReg, line):
24+
print(line)
25+
file.close()
26+
27+
if responseCodes:
28+
responseCodeReg = buildResponseCodeRegex(responseCodes)
29+
file = open(pathToFile, "r")
30+
for line in file:
31+
if re.findall(responseCodeReg, line):
32+
print(line)
33+
file.close()
1034

11-
responseCodeReg = buildResponseCodeRegex(responseCodes)
12-
httpMethodReg = buildHttpMethodRegex(httpMethods)
13-
file = open(pathToFile, "r")
14-
for line in file:
15-
if re.findall(httpMethodReg, line):
16-
print(line)

0 commit comments

Comments
 (0)