-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwork_and_education.go
378 lines (327 loc) · 10.5 KB
/
work_and_education.go
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
package facebook
import (
"github.com/tamboto2000/jsonextract/v3"
)
// Work contains Profile's work/occupation information
type Work struct {
Title string `json:"title,omitempty"`
CompanyURL string `json:"companyUrl,omitempty"`
Description string `json:"description,omitempty"`
DateStart string `json:"dateStart,omitempty"`
DateStartUnix int64 `json:"dateStartUnix,omitempty"`
DateEnd string `json:"dateEnd,omitempty"`
DateEndUnix int64 `json:"dateEndUnix,omitempty"`
CompanyIcon *Photo `json:"companyIcon,omitempty"`
Location string `json:"location,omitempty"`
}
// Education contain education information
type Education struct {
Title string `json:"title,omitempty"`
SchoolURL string `json:"schoolUrl,omitempty"`
// start and end date can't be determined
DateRange []string `json:"dateRange,omitempty"`
DateRangeUnix []int64 `json:"dateRangeUnix,omitempty"`
OtherInfo []string `json:"otherInfo,omitempty"`
Description string `json:"description,omitempty"`
SchoolIcon *Photo `json:"schoolIcon,omitempty"`
// college or secondary_school
Type string `json:"type,omitempty"`
}
// SyncWorkAndEducation retrieve Profile's work/occupation history and education history
func (about *About) SyncWorkAndEducation() error {
jsons, err := about.profile.reqAboutCollection(aboutWorkAndEducation)
if err != nil {
return err
}
for _, json := range jsons {
val, ok := json.Object()["label"]
if !ok {
continue
}
if val.String() == "ProfileCometAboutAppSectionQuery$defer$ProfileCometAboutAppSectionContent_appSection" {
works, educations := extractWorks(json)
about.WorkHistory = works
about.EducationHistory = educations
break
}
}
return nil
}
func extractWorks(json *jsonextract.JSON) ([]Work, []Education) {
works := make([]Work, 0)
educations := make([]Education, 0)
val, ok := json.Object()["data"]
if !ok {
return nil, nil
}
val, ok = val.Object()["activeCollections"]
if !ok {
return nil, nil
}
val, ok = val.Object()["nodes"]
if !ok {
return nil, nil
}
for _, node := range val.Array() {
val, ok := node.Object()["style_renderer"]
if !ok {
continue
}
val, ok = val.Object()["profile_field_sections"]
if !ok {
continue
}
for _, section := range val.Array() {
val, ok := section.Object()["field_section_type"]
if !ok {
continue
}
if val.String() == "work" {
// start parsing work history
val, ok := section.Object()["profile_fields"]
if !ok {
return nil, nil
}
val, ok = val.Object()["nodes"]
if !ok {
return nil, nil
}
for _, node := range val.Array() {
if node.Object()["field_type"].String() != "work" {
continue
}
// create Work and assign Title
work := Work{
Title: node.Object()["title"].Object()["text"].String(),
}
// find company url
if val, ok := node.Object()["title"].Object()["ranges"]; ok {
for _, rng := range val.Array() {
val, ok := rng.Object()["entity"]
if !ok {
continue
}
val, ok = val.Object()["url"]
if !ok {
continue
}
work.CompanyURL = val.String()
}
}
// find company icon
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["icon"]; ok {
work.CompanyIcon = &Photo{
Height: int(val.Object()["height"].Integer()),
URI: val.Object()["uri"].String(),
Width: int(val.Object()["width"].Integer()),
}
scale := val.Object()["scale"]
if scale.Kind() == jsonextract.Integer {
work.CompanyIcon.Scale = float64(scale.Integer())
} else {
work.CompanyIcon.Scale = scale.Float()
}
}
}
}
// find description
if val, ok := node.Object()["list_item_groups"]; ok {
for _, itemGroup := range val.Array() {
if val, ok := itemGroup.Object()["list_items"]; ok {
for _, item := range val.Array() {
val, ok := item.Object()["heading_type"]
if !ok {
continue
}
// description
if val.String() == "MEDIUM" {
if val, ok := item.Object()["text"]; ok {
work.Description = val.Object()["text"].String()
}
}
// can be date range or location
if val.String() == "LOW" {
if val, ok := item.Object()["text"]; ok {
// find date range with regex
// if non found, then this must be location, hopefully...
text := val.Object()["text"].String()
dates, datesStr := extractDate(text)
if len(dates) == 0 && len(datesStr) == 0 {
work.Location = text
} else {
if len(dates) == 2 {
var dateStartIdx int
var dateEndIdx int
if dates[0].Unix() < dates[1].Unix() {
dateStartIdx = 0
dateEndIdx = 1
} else {
dateStartIdx = 1
dateEndIdx = 0
}
work.DateStart = datesStr[dateStartIdx]
work.DateStartUnix = dates[dateStartIdx].Unix()
work.DateEnd = datesStr[dateEndIdx]
work.DateEndUnix = dates[dateEndIdx].Unix()
} else {
work.DateStart = datesStr[0]
work.DateStartUnix = dates[0].Unix()
}
}
}
}
}
}
}
}
works = append(works, work)
}
}
if val.String() == "college" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if node.Object()["field_type"].String() != "education" {
continue
}
education := Education{
Title: node.Object()["title"].Object()["text"].String(),
Type: "college",
}
// find school url
if val, ok := node.Object()["title"].Object()["ranges"]; ok {
for _, rng := range val.Array() {
if val, ok := rng.Object()["entity"]; ok {
if val, ok := val.Object()["url"]; ok {
education.SchoolURL = val.String()
}
}
}
}
// find school icon
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["icon"]; ok {
education.SchoolIcon = &Photo{
Height: int(val.Object()["height"].Integer()),
URI: val.Object()["uri"].String(),
Width: int(val.Object()["width"].Integer()),
}
scale := val.Object()["scale"]
if scale.Kind() == jsonextract.Integer {
education.SchoolIcon.Scale = float64(scale.Integer())
} else {
education.SchoolIcon.Scale = scale.Float()
}
}
}
}
// find date range, degree, concentrations, and description
if val, ok := node.Object()["list_item_groups"]; ok {
for _, val := range val.Array() {
if val, ok := val.Object()["list_items"]; ok {
for _, val := range val.Array() {
heading, ok := val.Object()["heading_type"]
if !ok {
continue
}
headStr := heading.String()
// extract date range
if headStr == "LOW" {
text := val.Object()["text"].Object()["text"].String()
dates, datesStr := extractDate(text)
education.DateRange = datesStr
for _, date := range dates {
education.DateRangeUnix = append(education.DateRangeUnix, date.Unix())
}
}
// extract other info, like degree, concentrations, and description
if headStr == "MEDIUM" {
education.OtherInfo = append(education.OtherInfo, val.Object()["text"].Object()["text"].String())
}
}
}
}
}
educations = append(educations, education)
}
}
}
}
if val.String() == "secondary_school" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if node.Object()["field_type"].String() != "education" {
continue
}
education := Education{
Title: node.Object()["title"].Object()["text"].String(),
Type: "secondary_school",
}
// find school url
if val, ok := node.Object()["title"].Object()["ranges"]; ok {
for _, rng := range val.Array() {
if val, ok := rng.Object()["entity"]; ok {
if val, ok := val.Object()["url"]; ok {
education.SchoolURL = val.String()
}
}
}
}
// find school icon
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["icon"]; ok {
education.SchoolIcon = &Photo{
Height: int(val.Object()["height"].Integer()),
URI: val.Object()["uri"].String(),
Width: int(val.Object()["width"].Integer()),
}
scale := val.Object()["scale"]
if scale.Kind() == jsonextract.Integer {
education.SchoolIcon.Scale = float64(scale.Integer())
} else {
education.SchoolIcon.Scale = scale.Float()
}
}
}
}
// find date range, degree, concentrations, and description
if val, ok := node.Object()["list_item_groups"]; ok {
for _, val := range val.Array() {
if val, ok := val.Object()["list_items"]; ok {
for _, val := range val.Array() {
heading, ok := val.Object()["heading_type"]
if !ok {
continue
}
headStr := heading.String()
// extract date range
if headStr == "LOW" {
text := val.Object()["text"].Object()["text"].String()
dates, datesStr := extractDate(text)
education.DateRange = datesStr
for _, date := range dates {
education.DateRangeUnix = append(education.DateRangeUnix, date.Unix())
}
}
// extract other info, like degree, concentrations, and description
if headStr == "MEDIUM" {
education.Description = val.Object()["text"].Object()["text"].String()
}
}
}
}
}
educations = append(educations, education)
}
}
}
}
}
}
return works, educations
}