-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplaces_lived.go
101 lines (89 loc) · 2.77 KB
/
places_lived.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
package facebook
import (
"github.com/tamboto2000/jsonextract/v3"
)
// Place contains profile's place info
type Place struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
PlaceIs string `json:"placeIs"`
Icon *Photo `json:"icon,omitempty"`
}
// SyncPlacesLived retrieve profile's places lived history
func (about *About) SyncPlacesLived() error {
jsons, err := about.profile.reqAboutCollection(aboutPlacesLived)
if err != nil {
return err
}
for _, json := range jsons {
if val, ok := json.Object()["label"]; ok {
if val.String() == "ProfileCometAboutAppSectionQuery$defer$ProfileCometAboutAppSectionContent_appSection" {
about.PlacesLived = extractPlaceLived(json)
break
}
}
}
return nil
}
func extractPlaceLived(json *jsonextract.JSON) []Place {
places := make([]Place, 0)
if val, ok := json.Object()["data"]; ok {
if val, ok := val.Object()["activeCollections"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
if val, ok := node.Object()["style_renderer"]; ok {
if val, ok := val.Object()["profile_field_sections"]; ok {
for _, section := range val.Array() {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for i, node := range val.Array() {
if i == 0 {
continue
}
place := Place{
Name: node.Object()["title"].Object()["text"].String(),
PlaceIs: node.Object()["field_type"].String(),
}
// extract place url
if val, ok := node.Object()["title"].Object()["ranges"]; ok {
if len(val.Array()) > 0 {
for _, rng := range val.Array() {
if val, ok := rng.Object()["entity"]; ok {
if val, ok := val.Object()["url"]; ok {
place.URL = val.String()
}
}
}
}
}
// extract icon
if val, ok := node.Object()["renderer"]; ok {
if val, ok := val.Object()["field"]; ok {
if val, ok := val.Object()["icon"]; ok {
place.Icon = &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 {
place.Icon.Scale = float64(scale.Integer())
} else {
place.Icon.Scale = scale.Float()
}
}
}
}
places = append(places, place)
}
}
}
}
}
}
}
}
}
}
return places
}