-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.py
106 lines (84 loc) · 3.18 KB
/
pipeline.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
import os
from dotenv import load_dotenv
from pyairtable import Api
load_dotenv()
ACCESS_TOKEN = os.environ['AIRTABLE_ACCESS_TOKEN']
BASE_ID = os.environ['BASE_ID']
def extract_interviews(fields: dict) -> list:
interviews = []
for (field, value) in fields.items():
if 'Client' in field:
num = field.split(' ')[-1]
status = fields.get('Status ' + num)
interviews.append({
'Email': fields.get('Name'),
'Cohort': fields.get('Cohort'),
'Company': value,
'Outcome': status,
'Style of Interview': "Unknown"
})
return interviews
def normalise_and_explode_interview(interview: dict):
outcome = interview['Outcome']
if not outcome:
return []
if outcome in ['Offer', 'Withdrawn', 'Stage 1', 'S1-Rejected', 'S1-Progress', "Turned down"]:
interview['Round'] = 'Stage 1'
if outcome == 'Stage 1':
interview['Round'] = 'Stage 1'
interview['Outcome'] = "Pending"
elif outcome == 'S1-Rejected':
interview['Round'] = 'Stage 1'
interview['Outcome'] = 'Fail'
elif outcome == 'S1-Progress':
interview['Round'] = 'Stage 1'
interview['Outcome'] = 'Progress'
elif outcome == 'Turned down':
interview['Round'] = 'Unknown Stage'
interview['Outcome'] = 'Turned down'
elif outcome == "Offer":
interview['Round'] = 'Unknown Stage'
interview['Outcome'] = 'Offer'
return []
if 'Stage' in outcome:
stage_num = int(outcome.split(" ")[1])
interview['Round'] = outcome
interview['Outcome'] = "Pending"
else:
stage_num = int(outcome.split("-")[0][1:])
interview['Round'] = f'Stage {stage_num}'
if 'Rejected' in outcome:
interview['Outcome'] = 'Fail'
else:
interview['Outcome'] = 'Progress'
previous_interview = {}
for (field, value) in interview.items():
previous_interview[field] = value
previous_interview['Outcome'] = f'S{stage_num - 1}-Progress'
return [previous_interview]
def main():
api = Api(ACCESS_TOKEN)
summary_table = api.table(BASE_ID, 'Summary')
tracker_table = api.table(BASE_ID, 'Interview Tracker')
print(ACCESS_TOKEN, BASE_ID)
summary_records = []
table_iter = summary_table.iterate()
while True:
try:
summary_records += next(table_iter)
except StopIteration:
break
interviews = []
for row in summary_table.all():
interviews += extract_interviews(row['fields'])
for interview in interviews:
interviews += normalise_and_explode_interview(interview)
interviews = filter(lambda interview: interview['Outcome'], interviews)
interviews = sorted(interviews, key=lambda interview: [
interview['Email'], interview['Round']])
# Less efficient than batch_create, but keeps the records in a logical order in views!
for interview in interviews:
print(interview)
print(tracker_table.create(interview, typecast=True))
if __name__ == "__main__":
main()