diff --git a/cash_flow.py b/cash_flow.py index eb1f7d1..d3e8083 100755 --- a/cash_flow.py +++ b/cash_flow.py @@ -13,17 +13,21 @@ from argparse import ArgumentParser + def per_month(out, income, savings, annual): - """ Returns an int of how much is left in monthly savings. """ + """Returns an int of how much is left in monthly savings.""" return int(savings + income - out - (annual / 12)) + parser = ArgumentParser() parser.add_argument("-o", "--out", help="Money going out", default=1, type=int) parser.add_argument("-s", "--savings", help="Savings", default=0, type=int) parser.add_argument( "-i", "--income", help="Money coming in", default=0, type=int ) -parser.add_argument("-a", "--annual", help="Annual expenses", default=0, type=int) +parser.add_argument( + "-a", "--annual", help="Annual expenses", default=0, type=int +) args = parser.parse_args() MAX_TEST = 24 diff --git a/data/jobs.txt b/data/jobs.txt index 3a0207a..4a93bff 100644 --- a/data/jobs.txt +++ b/data/jobs.txt @@ -1,3 +1,5 @@ -first_contact;last_contact;poc_name;company;notes;active;url;title -20230123;20230201;Fred Smythe; Some Great Place, LLC; linux, ansible, python; y; https://example.com/r12345; Senior Automation Engineer -20230101; 20230101; Jason Jayson; Can't read resume, Inc; Windows server, powershell; n; https://whocares.com; Winderz admin +poc_name; company; active; url; title; notes;first_contact;last_contact +Fred Smythe;Some Great Place, LLC;y;https://example.com/r12345;Senior Automation Engineer; python,linux,ansible;20220204;20230101 +Jason Jason;Not here Inc;n;https://whocares.com;Winderz admin;powershell;20230101;20230101 +Jim Jones;Hisco;Linux guy;y;hs.co;mostly doing ansible;20240321;20240321 +Sam Gamgee;The Shire;y;theshire.net/jobs/r12345;Server Gardner;lots of RHEL and Python;20240321;20240321 diff --git a/data/pocs.txt b/data/pocs.txt index e700fa2..b992eb8 100644 --- a/data/pocs.txt +++ b/data/pocs.txt @@ -1,4 +1,4 @@ -name;phone;email;first_contact;last_contact -Fred Smythe; 555.555.1212; fred@example.com; Example, Inc ; 20230123; 20202102 -Jayne Johnson; 123.456.7890; jj@otherexample.com; Other Recruiter, LLC; 20221212; 20221212 -Jason Jayson; br-549; jay@whocares.com; Whocares, Inc; 20230101; 20230101 +poc_name;phone;email;company;first_contact;last_contact +Fred Smythe;555.555.1212;fred@example.com;Example, Inc;20230123;20202102 +Jayne Johnson;123.456.7890;jj@otherexample.com;Other Recruiter, LLC;20221212;20221212 +Jason Jayson;br-549;jay@whocares.com;Whocares, Inc;20230101;20230101 diff --git a/job_seeker.py b/job_seeker.py index 0c05aac..fb76466 100755 --- a/job_seeker.py +++ b/job_seeker.py @@ -28,12 +28,14 @@ def __init__(self, job_data={}): self.first_contact = job_data.get( "first_contact", convert_date(dt.now()) ) + self.make_raw_data() self.searchables = [ self.title.lower(), self.notes.lower(), self.company.lower(), self.url.lower(), self.poc_name.lower(), + self.raw_data.lower(), ] def __str__(self): @@ -52,42 +54,57 @@ def __str__(self): self.first_contact, ) - -def job_builder(line): - _list = string_to_list(line) - data = { - "last_contact": _list[0], - "first_contact": _list[1], - "poc_name": _list[2], - "company": _list[3], - "notes": _list[4], - "active": _list[5], - "url": _list[6], - "title": _list[7], - } - return Job(data) + def make_raw_data(self): + """Creates the line properly.""" + self.raw_data = ";".join( + [ + self.poc_name, + self.company, + self.active, + self.url, + self.title, + self.notes, + self.first_contact, + self.last_contact, + ] + ) class POC: """Stores the contact info for each Point of Contact""" def __init__(self, data={}): - self.name = data.get("name", "") + self.poc_name = data.get("poc_name", "") self.company = data.get("company", "") self.phone = data.get("phone", "") self.email = data.get("email", "") self.first_contact = data.get("first_contact", convert_date(dt.now())) self.last_contact = data.get("last_contact", convert_date(dt.now())) + self.make_raw_data() self.searchables = [ - self.name.lower(), + self.poc_name.lower(), self.company.lower(), self.email.lower(), + self.raw_data.lower(), ] + def make_raw_data(self): + """Creates the line properly.""" + self.raw_data = ";".join( + [ + self.poc_name, + self.company, + self.phone, + self.email, + self.first_contact, + self.last_contact, + ] + ) + def __str__(self): """Returns a formatted string with the POC info""" return "{}, ({}) {} [{}]\nFirst Contact: {}, Last Contact: {}".format( - self.name, + self.poc_name, self.phone, self.email, self.company, @@ -96,17 +113,41 @@ def __str__(self): ) -def poc_builder(line): - _list = string_to_list(line) - data = { - "name": _list[0], - "phone": _list[1], - "email": _list[2], - "company": _list[3], - "first_contact": _list[4], - "last_contact": _list[5], - } - return POC(data) +def builder(data, klass): + if type(data) == dict: + return klass(data) + _list = string_to_list(data) + today = convert_date(dt.now()) + if klass == POC: + if len(_list) < 5: + _list.append(today) + if len(_list) < 6: + _list.append(today) + data = { + "poc_name": _list[0], + "phone": _list[1], + "email": _list[2], + "company": _list[3], + "first_contact": _list[4], + "last_contact": _list[5], + } + return POC(data) + elif klass == Job: + if len(_list) < 7: + _list.append(today) + if len(_list) < 8: + _list.append(today) + data = { + "poc_name": _list[0], + "company": _list[1], + "active": _list[2], + "url": _list[3], + "title": _list[4], + "notes": _list[5], + "first_contact": _list[6], + "last_contact": _list[7], + } + return Job(data) def convert_date(date): @@ -131,9 +172,9 @@ def parse_list(_list, _list_type, search): for element in _list: if search.lower() in element.lower(): if _list_type == "poc": - items.append(poc_builder(element)) + items.append(builder(element, POC)) if _list_type == "job": - items.append(job_builder(element)) + items.append(builder(element, Job)) return items @@ -145,10 +186,11 @@ def string_to_list(data, sep=";"): def items_from_file(filename, klass): """Takes a filename, and returns objects based on that file.""" with open(filename, "r") as f: + # results = [builder(row, klass) for row in f.readlines()] reader = csv.DictReader(f, delimiter=";") - result = [klass(row) for row in reader] + results = [builder(row, klass) for row in reader] - return result + return results def search_items(search_term, *lists): @@ -166,21 +208,35 @@ def search_items(search_term, *lists): return results +def write_file(filename, data, string): + """Writes the data in the proper format.""" + with open(filename, "w") as f: + f.write(string + "\n") + for item in data: + f.write(item.raw_data + "\n") + + if __name__ == "__main__": datadir = "data" - job_file = "jobs.txt" - poc_file = "pocs.txt" - + job_file = os.path.join(datadir, "jobs.txt") + poc_file = os.path.join(datadir, "pocs.txt") + JOB_STRING = "poc_name; company; active; url; title; notes" + POC_STRING = "poc_name; phone; email; company" + INFO_STRING = """ + Here are the formats, use semi-colons to separate data. + Sections can be empty, just include the semi-colon seperator. + Contact dates will default to the date of entry. + """ try: - poc_list = items_from_file(os.path.join(datadir, poc_file), POC) - job_list = items_from_file(os.path.join(datadir, job_file), Job) - except: - print("Can't find the data files") + poc_list = items_from_file(poc_file, POC) + job_list = items_from_file(job_file, Job) + except Exception as e: + print("Can't find the data files", e) sys.exit(1) parser = argparse.ArgumentParser() parser.add_argument( - "-a", "--add", help="add data, requires -r or -p", action="store_true" + "-a", "--add", help="add DATA, requires -j or -p", action="store_true" ) parser.add_argument( "-j", "--job", help="use the Job info", action="store_true" @@ -192,9 +248,23 @@ def search_items(search_term, *lists): args = parser.parse_args() if args.add: - print("I am to add") + print(INFO_STRING) + print("Jobs: \n\t {}".format(JOB_STRING)) + print("POCs: \n\t {}".format(POC_STRING)) + data = input("> ") + if args.job: + job_list.append(builder(data, Job)) + write_file(job_file, job_list, JOB_STRING + ";first_contact;last_contact") + elif args.poc: + poc_list.append(builder(data, POC)) + write_file(poc_file, poc_list, POC_STRING + ";first_contact;last_contact") + else: + print("I am to add, but you give me no details.") + sys.exit(1) if args.search: results = search_items(args.search, job_list, poc_list) + for job in job_list: + print(job) for result in results: print(result, "\n")