File size: 16,451 Bytes
9b3b1bc
 
 
 
24de2aa
9b3b1bc
 
 
 
 
 
 
 
 
 
 
 
 
 
0795ce5
9b3b1bc
 
 
 
 
 
 
0795ce5
9b3b1bc
 
 
3588e6d
 
 
 
 
 
 
 
 
24de2aa
42ca295
fc51d61
 
 
42ca295
0795ce5
fc51d61
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc51d61
42ca295
 
 
 
 
0795ce5
fc51d61
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
b7c28ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3588e6d
 
 
 
fc51d61
42ca295
 
fc51d61
42ca295
 
0795ce5
fc51d61
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42ca295
 
 
 
 
fc51d61
0795ce5
fc51d61
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42ca295
 
 
 
 
 
0795ce5
fc51d61
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42ca295
 
 
 
 
 
0795ce5
fc51d61
 
 
 
3588e6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fc51d61
42ca295
 
 
 
 
0795ce5
fc51d61
 
 
 
 
 
 
 
 
 
 
 
3588e6d
fc51d61
42ca295
 
 
 
 
 
 
fc51d61
0795ce5
fc51d61
 
 
 
 
3588e6d
fc51d61
 
 
 
 
 
3588e6d
fc51d61
42ca295
 
fc51d61
24de2aa
 
 
0795ce5
24de2aa
 
 
 
 
 
 
 
 
 
 
 
 
 
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import requests
from bs4 import BeautifulSoup
from cleantext import clean
import pandas as pd
import numpy as np

onet = pd.read_csv('static/ONET_JobTitles.csv')
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

def remove_new_line(value):
        return ''.join(value.splitlines())

def get_onet_code(jobtitle):
    onetCode = onet.loc[onet['JobTitle'] == jobtitle, 'onetCode']
    onetCode = onetCode.reindex().tolist()[0]
    return onetCode

def get_onet_description(onetCode):
    url = "https://www.onetonline.org/link/summary/" + onetCode
    response = requests.get(url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    jobdescription = soup.p.get_text()
    return jobdescription

def get_onet_tasks(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}
    url = "https://www.onetonline.org/link/result/" + onetCode + "?c=tk&n_tk=0&s_tk=IM&c_tk=0"
    response = requests.get(url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('occupations related to multiple tasks')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace("core", " - ").replace("supplemental", "").replace("not available", "").replace(" )importance category task", "").replace(" find ", "")
        tasks = tasks.split(". ")
        tasks = [''.join(map(lambda c: '' if c in '0123456789-' else c, task)) for task in tasks]
        return tasks
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])

def get_onet_activities(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}
    
    activities_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=wa&n_wa=0&s_wa=IM&c_wa=0"

    response = requests.get(activities_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace("importance work activity", " ")
        tasks = tasks.split(". ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(' ) ', '')])
        df = pd.DataFrame(num_desc, columns = ['Importance', 'Activity'])
        df = df[df['Importance'] != '']
        activities = df
        return activities
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])

    
def get_onet_context(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    context_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=cx&n_cx=0&c_cx=0&s_cx=n"

    response = requests.get(context_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace("importance work activity", " ")
        tasks = tasks.split("? ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
        df2 = pd.DataFrame(num_desc, columns = ['Importance', 'Condition'])
        df2 = df2[df2['Importance'] != '']
        context = df2
        if len(context.index) < 5:
            context_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=wc&n_wc=0&c_wc=0"
            response = requests.get(context_url, headers=headers, verify=False)
            soup = BeautifulSoup(response.text, 'html.parser')
            tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
            tasks = clean(tasks)
            if len(tasks.split('show all show top 10')) > 1:
                tasks = tasks.split('show all show top 10')[1]
                tasks = tasks.split('back to top')[0]
                tasks = remove_new_line(tasks).replace("related occupations", " ").replace("importance work activity", " ")
                tasks = tasks.split("? ")
                split_data = [item.split(" -- ")[0] for item in tasks]
                num_desc = []
                for i in range(len(tasks)):
                    temp = [','.join(item) for item in split_data][i].split(',')
                    num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
                df2 = pd.DataFrame(num_desc, columns = ['Importance', 'Condition'])
                df2 = df2[df2['Importance'] != '']
                context = df2
        return context
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])


def get_onet_skills(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    skills_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=sk&n_sk=0&s_sk=IM&c_sk=0"
    
    response = requests.get(skills_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance skill", " ")
        tasks = tasks.split(". ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
        df3 = pd.DataFrame(num_desc, columns = ['Importance', 'Skill'])
        df3 = df3[df3['Importance'] != '']
        skills = df3
        return skills
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])


def get_onet_knowledge(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    knowledge_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=kn&n_kn=0&s_kn=IM&c_kn=0"

    response = requests.get(knowledge_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance knowledge", " ")
        tasks = tasks.split(". ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
        df4 = pd.DataFrame(num_desc, columns = ['Importance', 'Knowledge'])
        df4 = df4[df4['Importance'] != '']
        knowledge = df4
        return knowledge
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])


def get_onet_abilities(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    abilities_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=ab&n_ab=0&s_ab=IM&c_ab=0"

    response = requests.get(abilities_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    if len(tasks.split('show all show top 10')) > 1:
        tasks = tasks.split('show all show top 10')[1]
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance ability", " ")
        tasks = tasks.split(". ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
        df5 = pd.DataFrame(num_desc, columns = ['Importance', 'Ability'])
        df5 = df5[df5['Importance'] != '']
        abilities = df5
        return abilities
    else:
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])
        
    

def get_onet_interests(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    interests_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=in&c_in=0"

    response = requests.get(interests_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    tasks = tasks.split("occupational interest interest")[1]#.replace('bright outlook', '').replace('updated 2023', '')
    if len(tasks.split('back to top')) > 1:
        tasks = tasks.split('back to top')[0]
        tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance interest", " ")
        tasks = tasks.split(". ")
        split_data = [item.split(" -- ")[0] for item in tasks]
        num_desc = []
        for i in range(len(tasks)):
            temp = [','.join(item) for item in split_data][i].split(',')
            num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
        df6 = pd.DataFrame(num_desc, columns = ['Importance', 'Interest'])
        df6 = df6[df6['Importance'] != '']
        interests = df6
        return interests
    else: 
        return pd.DataFrame([("We're sorry."), ("This occupation is currently undergoing updates."), ("Please try again later.")])


def get_onet_values(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    values_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=wv&c_wv=0"
    
    response = requests.get(values_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    tasks = tasks.split('extent work value')[1]
    tasks = tasks.split('back to top')[0]
    tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance value", " ")
    tasks = tasks.split(". ")
    split_data = [item.split(" -- ")[0] for item in tasks]
    num_desc = []
    for i in range(len(tasks)):
        temp = [','.join(item) for item in split_data][i].split(',')
        num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
    df7 = pd.DataFrame(num_desc, columns = ['Importance', 'Value'])
    df7 = df7[df7['Importance'] != '']
    values = df7
    return values

def get_onet_styles(onetCode):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}

    style_url = "https://www.onetonline.org/link/result/" + onetCode + "?c=ws&n_ws=0&c_ws=0"

    response = requests.get(style_url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    tasks = str(soup.get_text('reportsubdesc')).replace("reportsubdesc", " ").replace("ImportanceCategoryTask ", "")
    tasks = clean(tasks)
    tasks = tasks.split('show all show top 10')[1]
    tasks = tasks.split('back to top')[0]
    tasks = remove_new_line(tasks).replace("related occupations", " ").replace(")importance work style", "").replace(")importance style", " ")
    tasks = tasks.split(". ")
    split_data = [item.split(" -- ")[0] for item in tasks]
    num_desc = []
    for i in range(len(tasks)):
        temp = [','.join(item) for item in split_data][i].split(',')
        num_desc.append([''.join([c for c in temp if c in '0123456789']), ''.join([c for c in temp if c not in '0123456789']).replace(')context work context', '')])
    df8 = pd.DataFrame(num_desc, columns = ['Importance', 'Style'])
    df8 = df8[df8['Importance'] != '']
    styles = df8
    return styles

def get_job_postings(onetCode, state):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15'}
    url = "https://www.onetonline.org/link/localjobs/" + onetCode + "?st=" + state
    response = requests.get(url, headers=headers, verify=False)
    soup = BeautifulSoup(response.text, 'html.parser')
    jobs = str(soup.get_text("tbody")).split('PostedtbodyTitle and CompanytbodyLocation')[1].split('Sources:')[0].split("tbody")
    jobs = jobs[5:45]
    starts = np.linspace(start=0, stop=len(jobs)-4,num= 10)
    stops = np.linspace(start=3, stop=len(jobs)-1, num= 10)
    jobpostings = []
    for i in range(0,10):
        jobpostings.append(str([' '.join(jobs[int(starts[i]):int(stops[i])])]).replace("['", '').replace("']", ''))
    links = str(soup.find_all('a', href=True)).split("</small>")[1].split(', <a href="https://www.careeronestop.org/"')[0].split(' data-bs-toggle="modal" ')
    linklist = []
    for i in range(1, len(links)):
        links[i] = "https://www.onetonline.org" + str(links[i]).split(' role="button">')[0].replace("href=", "")
        linklist.append(links[i].replace('"', ''))
    return jobpostings, linklist