-
Notifications
You must be signed in to change notification settings - Fork 1
/
job_seeker.py
executable file
·239 lines (207 loc) · 7.14 KB
/
job_seeker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env python
# name: job_seeker.py
# version: 0.0.1
# date: 20211129
# author: Leam Hall
# desc: Track data on job applications
import argparse
import csv
from datetime import datetime as dt
import os.path
import sys
class Job:
"""Stores the job req data"""
def __init__(self, job_data={}):
self.title = job_data.get("title", "")
self.active = job_data.get("active", "y")
self.notes = job_data.get("notes", "")
self.company = job_data.get("company", "")
self.url = job_data.get("url", "")
self.poc_name = job_data.get("poc_name", "")
self.last_contact = job_data.get(
"last_contact", convert_date(dt.now())
)
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):
if self.active == "y":
self.active = "Yes"
else:
self.active = "No"
return "Title: {}\nActive: {}\nNotes: {}\nCompany: {}\nURL: {}\nPOC: {} \nLast contact: {}\nFirst contact: {}".format(
self.title,
self.active,
self.notes,
self.company,
self.url,
self.poc_name,
self.last_contact,
self.first_contact,
)
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 Company:
"""Stores the key, name, url, and POCs for a company"""
def __init__(self, data={}):
self.key = data.get("key", "").lower()
self.name = data.get("name", "")
self.job_url = data.get("job_url", "")
def make_poc_list(self, pocs):
return []
class POC:
"""Stores the contact info for each Point of Contact"""
def __init__(self, data={}):
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.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.poc_name,
self.phone,
self.email,
self.company,
self.first_contact,
self.last_contact,
)
def builder(data, klass):
"""Return an object based on a data dict"""
today = convert_date(dt.now())
if type(data) is dict:
if data["first_contact"] is None:
data["first_contact"] = today
if data["last_contact"] is None:
data["last_contact"] = today
return klass(data)
else:
raise ValueError("Requires a dict input")
def convert_date(date):
"""Takes a datetime.datetime object and returns a YYYMMDD string"""
return "{}{:0>2}{:0>2}".format(date.year, date.month, date.day)
def string_to_list(data, sep=";"):
"""Takes a sep separated string and converts it to a list"""
return [e.strip() for e in data.split(sep)]
def items_from_file(filename, klass):
"""Takes a filename, and returns objects based on that file."""
results = list()
with open(filename, "r") as f:
reader = csv.DictReader(f, delimiter=";")
results = [builder(row, klass) for row in reader]
return results
def search_items(search_term, *lists):
"""
Searches the values of each item in a list of objects.
Returns a list of objects with the search_term.
"""
results = []
for _list in lists:
for item in _list:
for searchable in item.searchables:
if search_term.lower() in searchable:
results.append(item)
break
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 = os.path.join(datadir, "jobs.txt")
poc_file = os.path.join(datadir, "pocs.txt")
JOB_STRING = (
"poc_name;company;active;url;title;notes;first_contact;last_contact"
)
POC_STRING = "poc_name;phone;email;company;first_contact;last_contact"
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(poc_file, POC)
print("about to do items_from_file on jobs.")
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 -j or -p", action="store_true"
)
parser.add_argument(
"-j", "--job", help="use the Job info", action="store_true"
)
parser.add_argument(
"-p", "--poc", help="use the POC info", action="store_true"
)
parser.add_argument("-s", "--search", help="SEARCH for", default="")
args = parser.parse_args()
if args.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 result in results:
print(result, "\n")