From 7fbdf7073ae096cd58d434f30ab4df00a4be9e26 Mon Sep 17 00:00:00 2001 From: zebde Date: Sat, 23 Sep 2017 12:47:52 +0100 Subject: [PATCH 1/2] Landscape fixes --- iplookup.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/iplookup.py b/iplookup.py index 3b0b659..9f9b4ea 100644 --- a/iplookup.py +++ b/iplookup.py @@ -14,8 +14,8 @@ from joblib import Parallel, delayed from netaddr import AddrFormatError, IPSet -torcsv = 'Tor_ip_list_ALL.csv' -sfile = 'http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv' +TORCSV = 'Tor_ip_list_ALL.csv' +SFILE = 'http://torstatus.blutmagie.de/ip_list_all.php/Tor_ip_list_ALL.csv' SUBNET = 0 INPUTDICT = {} SECTOR_CSV = 'sector.csv' @@ -46,14 +46,14 @@ def lookup(value): return value -def flookup(value, fname, sfile): +def flookup(value, fname, SFILE): """Look up a value in a file.""" try: fhandle = open(fname) except IOError: sourceFile = urllib.URLopener() sourceFile.retrieve( - sfile, + SFILE, fname) fhandle = open(fname) search = mmap.mmap(fhandle.fileno(), 0, access=mmap.ACCESS_READ) @@ -119,7 +119,7 @@ def mainlookup(var): country = match.country location = match.location - tor = flookup(var, torcsv, sfile) + tor = flookup(var, TORCSV, SFILE) category = identify(origin[4]) if category == "": @@ -162,7 +162,7 @@ def mainlookup(var): def batch(inputfile): """Handle batch lookups using file based input.""" - if os.path.isfile(OUTFILE): + if os.path.iSFILE(OUTFILE): os.remove(OUTFILE) fhandle = open(OUTFILE, "a") header = 0 @@ -221,12 +221,12 @@ def main(): required="false", metavar="value", help="The value of the request") - ARGS = PARSER.parse_args() + args = PARSER.parse_args() - if ARGS.t == "single": - print(single(ARGS.v)) - elif ARGS.t == "batch": - batch(ARGS.v) + if args.t == "single": + print(single(args.v)) + elif args.t == "batch": + batch(args.v) else: PARSER.print_help() From 86a7ebef8c02101cc8a07cb8eba74482c643c51b Mon Sep 17 00:00:00 2001 From: zebde Date: Sat, 23 Sep 2017 12:51:14 +0100 Subject: [PATCH 2/2] Landscape fixes --- iplookup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iplookup.py b/iplookup.py index 9f9b4ea..90435b8 100644 --- a/iplookup.py +++ b/iplookup.py @@ -211,24 +211,24 @@ def csvout(inputdict): def main(): import argparse - PARSER = argparse.ArgumentParser() - PARSER.add_argument("-t", + parser = argparse.Argumentparser() + parser.add_argument("-t", choices=('single', 'batch'), required="false", metavar="request-type", help="Either single or batch request") - PARSER.add_argument("-v", + parser.add_argument("-v", required="false", metavar="value", help="The value of the request") - args = PARSER.parse_args() + args = parser.parse_args() if args.t == "single": print(single(args.v)) elif args.t == "batch": batch(args.v) else: - PARSER.print_help() + parser.print_help() if __name__ == "__main__":