-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcandidate.py
99 lines (85 loc) · 3.9 KB
/
candidate.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
from datetime import datetime
import pytz
import re
import data_config
class Candidate:
def __init__(self, candidate):
self.candidate = candidate
self._extract_candidate_info()
delattr(self, "candidate")
def _remove_whitespace(self, value, sep):
if value is not None:
value = str(value).strip().replace("\t", " ")
value = re.sub('\n\n+','\n',value)
value = value.replace("\n", sep)
return value
def _convert_timestamp_to_utc_string(self, unix_timestamp):
timestamp_without_miliseconds = unix_timestamp / 1000.0
tz = pytz.timezone("America/Los_Angeles")
return datetime.fromtimestamp(timestamp_without_miliseconds, tz).strftime(
"%Y-%m-%d %H:%M:%S"
)
def _convert_timestamp_to_date_string(self, unix_timestamp):
timestamp_without_miliseconds = unix_timestamp / 1000.0
tz = pytz.timezone("America/Los_Angeles")
return datetime.fromtimestamp(timestamp_without_miliseconds, tz).strftime("%Y-%m-%d")
def _extract_candidate_info(self):
self._extract_candidate_fields()
self._extract_application_fields()
self._extract_job_fields()
self._extract_custom_application_fields()
self._extract_custom_job_fields()
def _extract_candidate_fields(self):
self.candidate_eid = self.candidate.get("eId")
for field in data_config.candidate_fields:
value = self._remove_whitespace(self.candidate.get(field, "")," ")
setattr(self, field, value)
def _extract_application_fields(self):
application = self.candidate.get("application")
self.application_eid = application.get("eId")
self.lastUpdatedDate = self._convert_timestamp_to_utc_string(
application.get("lastUpdatedDate")
)
if application.get("startDate") is not None:
self.startDate = self._convert_timestamp_to_date_string(
application.get("startDate")
)
else:
self.startDate = None
if application.get("hireDate") is not None:
self.hireDate = self._convert_timestamp_to_date_string(
application.get("hireDate")
)
else:
self.hireDate = None
for field in data_config.application_fields:
value = self._remove_whitespace(application.get(field, "")," ")
setattr(self, field, value)
def _extract_job_fields(self):
job = self.candidate.get("application").get("job")
self.job_eid = job.get("eId")
for field in data_config.job_fields:
value = self._remove_whitespace(job.get(field)," ")
setattr(self, field, value)
def _extract_custom_job_fields(self):
custom_job_fields = self.candidate.get("application").get("job").get("customField")
for f in data_config.custom_job_fields.keys():
setattr(self, f, "")
if custom_job_fields is not None:
for field in custom_job_fields:
key = field.get("fieldCode")
value = self._remove_whitespace(field.get("value", "")," ")
if key in data_config.custom_job_fields.keys():
setattr(self, key, value)
def _extract_custom_application_fields(self):
custom_application_fields = self.candidate.get("application").get("customField")
for f in data_config.custom_application_fields.keys():
setattr(self, f, "")
for field in custom_application_fields:
key = field.get("fieldCode")
if key not in data_config.fields_format_newlines:
value = self._remove_whitespace(field.get("value", "")," ")
else:
value = self._remove_whitespace(field.get("value", "")," | ")
if key in data_config.custom_application_fields.keys():
setattr(self, key, value)