Skip to content

Commit 0d32905

Browse files
authored
Updated command_line.py for specifying explicit skills file for brute forcing
1 parent 2bd51b2 commit 0d32905

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

pyresparser/command_line.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import os
44
import argparse
55
from pprint import pprint
6-
from pyresparser import ResumeParser
6+
import io
7+
import csv
78
import multiprocessing as mp
89
from urllib.request import Request, urlopen
9-
import io
10+
from pyresparser import ResumeParser
11+
from itertools import product
1012

1113
def print_cyan(text):
1214
print("\033[96m {}\033[00m" .format(text))
@@ -17,39 +19,49 @@ def __init__(self):
1719
self.__parser.add_argument('-f', '--file', help="resume file to be extracted")
1820
self.__parser.add_argument('-d', '--directory', help="directory containing all the resumes to be extracted")
1921
self.__parser.add_argument('-r', '--remotefile', help="remote path for resume file to be extracted")
20-
return
22+
self.__parser.add_argument('-sf', '--skillsfile', help="custom skills CSV file against which skills are searched for")
2123

2224
def extract_resume_data(self):
2325
args = self.__parser.parse_args()
2426

2527
if args.remotefile:
2628
return self.__extract_from_remote_file(args.remotefile)
2729
if args.file and not args.directory:
28-
return self.__extract_from_file(args.file)
30+
if args.skillsfile:
31+
return self.__extract_from_file(args.file, args.skillsfile)
32+
else:
33+
return self.__extract_from_file(args.file)
2934
elif args.directory and not args.file:
30-
return self.__extract_from_directory(args.directory)
35+
if args.skillsfile:
36+
return self.__extract_from_directory(args.directory, args.skillsfile)
37+
else:
38+
return self.__extract_from_directory(args.directory)
3139
else:
32-
return 'Invalid option. Please provide a valid option.'
40+
self.__parser.print_help()
3341

34-
def __extract_from_file(self, file):
42+
def __extract_from_file(self, file, skills_file=None):
3543
if os.path.exists(file):
3644
print_cyan('Extracting data from: {}'.format(file))
37-
resume_parser = ResumeParser(file)
45+
if skills_file:
46+
resume_parser = ResumeParser(file, skills_file)
47+
else:
48+
resume_parser = ResumeParser(file)
3849
return [resume_parser.get_extracted_data()]
3950
else:
4051
return 'File not found. Please provide a valid file name.'
4152

42-
def __extract_from_directory(self, directory):
53+
def __extract_from_directory(self, directory, skills_file=None):
4354
if os.path.exists(directory):
4455
pool = mp.Pool(mp.cpu_count())
4556

4657
resumes = []
47-
data = []
48-
for root, directories, filenames in os.walk(directory):
58+
for root, _, filenames in os.walk(directory):
4959
for filename in filenames:
5060
file = os.path.join(root, filename)
51-
resumes.append(file)
52-
61+
if skills_file:
62+
resumes.append([file, skills_file])
63+
else:
64+
resumes.append(file)
5365
results = pool.map(resume_result_wrapper, resumes)
5466
pool.close()
5567
pool.join()
@@ -67,11 +79,15 @@ def __extract_from_remote_file(self, remote_file):
6779
resume_parser = ResumeParser(_file)
6880
return [resume_parser.get_extracted_data()]
6981

70-
def resume_result_wrapper(resume):
71-
print_cyan('Extracting data from: {}'.format(resume))
72-
parser = ResumeParser(resume)
82+
def resume_result_wrapper(args):
83+
if len(args) == 2:
84+
print_cyan('Extracting data from: {}'.format(args[0]))
85+
parser = ResumeParser(args[0], args[1])
86+
else:
87+
print_cyan('Extracting data from: {}'.format(args))
88+
parser = ResumeParser(args)
7389
return parser.get_extracted_data()
7490

7591
def main():
7692
cli_obj = ResumeParserCli()
77-
pprint(cli_obj.extract_resume_data())
93+
pprint(cli_obj.extract_resume_data())

0 commit comments

Comments
 (0)