-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass_upload.py
174 lines (149 loc) · 5.18 KB
/
mass_upload.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
import numpy as np
import pandas as pd
import requests
import json
CUSTOM_PROFILE_FIELDS = [
'vector_affiliation_categories',
'approved_profile',
'vector_affiliation',
'if_you_are_associated_with_a_vector_faculty_or_faculty_affiliate_please_state_their_name_here',
'what_is_your_estimated_graduation_date_if_still_studying',
'if_you_chose_otherunsure_please_explain',
'preferred_pronoun',
'verified_linkedin_url',
'what_are_your_primary_areas_of_research_interest_please_select_the_top_3_from_the_list_below',
'what_is_your_highest_level_of_education_note_if_currently_enrolled_please_include_this_level',
'what_is_your_level_of_experience_this_could_be_through_internships_phd_research_experience_or_industry_experience_post_graduation',
'what_is_your_program_of_study',
'what_sectors_interest_you',
'opportunities_you_are_looking_for',
'what_types_of_roles_are_you_looking_for',
'which_ontario_university_did_you_attend_most_recent_education',
]
CUSTOM_JOB_FIELDS = [
'company_size',
'email_applications_or_application_click_through',
'job_industry',
'level_of_experience',
'minimum_degree_level',
'new_posting_or_repost'
]
CUSTOM_EMPLOYER_FIELDS = [
'approval_notes',
'approved_employer',
'industry_sector',
'relationship_to_the_vector_institute',
]
class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
elif isinstance(obj, np.floating):
return float(obj)
elif isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, np.bool_):
return bool(obj)
return super(NpEncoder, self).default(obj)
def jobs_mass_upload(df: pd.DataFrame, key: str) -> None:
# REQUIRED_FIELDS = [
# 'token',
# 'title',
# 'company',
# 'location',
# 'description',
# 'contact_email',
# 'apply_email',
# 'apply_url',
# ]
url = "https://canadaai.jobboard.io/api/v1/jobs/"
headers = {
"X-Api-Key": key,
'accept': 'text/plain',
"JobBoardioURL": "https://talenthub.vectorinstitute.ai/",
'content-type' : 'application/json'
}
fields = df.columns
# for field in REQUIRED_FIELDS:
# if not any(field == fields):
# raise ValueError(f'Did not supply all required fields: {field}')
for i in range(df.shape[0]):
token = df['token'][i]
curr_url = url + str(token)
payload = dict()
for field in fields:
if field == 'token':
continue
if field in CUSTOM_JOB_FIELDS:
if not ('custom_field_answers' in payload.keys()):
payload['custom_field_answers'] = {}
payload['custom_field_answers'][field] = df[field][i]
else:
payload[field] = df[field][i]
r = requests.request(
"PATCH",
curr_url,
data = json.dumps(payload, cls = NpEncoder),
headers=headers
)
print(r.text)
print(r.status_code)
return None
def profiles_mass_upload(df: pd.DataFrame, key: str) -> None:
url = "https://canadaai.jobboard.io/api/v1/profiles/"
headers = {
"X-Api-Key": key,
'accept': 'text/plain',
"JobBoardioURL": "https://talenthub.vectorinstitute.ai/",
'content-type' : 'application/json'
}
fields = df.columns
for i in range(df.shape[0]):
token = df['id'][i]
curr_url = url + str(token)
payload = dict()
for field in fields:
if field == 'id':
continue
if field in CUSTOM_PROFILE_FIELDS:
if not ('custom_field_answers' in payload.keys()):
payload['custom_field_answers'] = {}
payload['custom_field_answers'][field] = df[field][i]
else:
payload[field] = df[field][i]
r = requests.request(
"PATCH",
curr_url,
data = json.dumps(payload, cls = NpEncoder),
headers=headers
)
return None
def employers_mass_upload(df: pd.DataFrame, key: str) -> None:
url = "https://canadaai.jobboard.io/api/v1/employers/"
headers = {
"X-Api-Key": key,
'accept': 'text/plain',
"JobBoardioURL": "https://talenthub.vectorinstitute.ai/",
'content-type' : 'application/json'
}
fields = df.columns
for i in range(df.shape[0]):
token = df['id'][i]
curr_url = url + str(token)
payload = dict()
for field in fields:
if field == 'id':
continue
if field in CUSTOM_EMPLOYER_FIELDS:
if not ('custom_field_answers' in payload.keys()):
payload['custom_field_answers'] = {}
payload['custom_field_answers'][field] = df[field][i]
else:
payload[field] = df[field][i]
r = requests.request(
"PATCH",
curr_url,
data = json.dumps(payload, cls = NpEncoder),
headers=headers
)
return None