-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontact_and_basic_info.go
234 lines (207 loc) · 7.23 KB
/
contact_and_basic_info.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
package facebook
import (
"strings"
"github.com/tamboto2000/jsonextract/v3"
)
// ContactAndBasicInfo contains profile's contact detail and basic info
type ContactAndBasicInfo struct {
Phone string `json:"phone,omitempty"`
Address string `json:"address,omitempty"`
Websites []string `json:"websites,omitempty"`
SocialLinks []SocialLink `json:"socialLinks,omitempty"`
BasicInfo *BasicInfo `json:"basicInfo,omitempty"`
}
// SocialLink contains social media url and its type/social media platform name
type SocialLink struct {
// can be an URL or screenname/username
URLOrScreenname string `json:"urlOrScreenname"`
Type string `json:"type"`
}
// BasicInfo contains profile's about basic info, such as gender, birthday, sexual preferences, etc.
type BasicInfo struct {
Gender string `json:"gender,omitempty"`
Birthday string `json:"birthday,omitempty"`
Languages string `json:"languages,omitempty"`
ReligiousViews string `json:"religiousViews,omitempty"`
PoliticalViews string `json:"politicalViews,omitempty"`
InterestedIn string `json:"interestedIn,omitempty"`
}
// SyncContactAndBasicInfo retrieve profile's basic contact and info
func (about *About) SyncContactAndBasicInfo() error {
jsons, err := about.profile.reqAboutCollection(aboutContactAndBasicInfo)
if err != nil {
return err
}
for _, json := range jsons {
val, ok := json.Object()["label"]
if !ok {
continue
}
if val.String() == "ProfileCometAboutAppSectionQuery$defer$ProfileCometAboutAppSectionContent_appSection" {
about.ContactAndBasicInfo = extractContactBasicInfo(json)
break
}
}
return nil
}
func extractContactBasicInfo(json *jsonextract.JSON) *ContactAndBasicInfo {
contactBasic := new(ContactAndBasicInfo)
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() {
val, ok := section.Object()["field_section_type"]
if !ok {
continue
}
// extract phone number and address
if val.String() == "about_contact_info" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
val, ok := node.Object()["field_type"]
if !ok {
continue
}
// extract phone
if val.String() == "other_phone" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.Phone = val.String()
}
}
}
// extract address
if val.String() == "address" {
if val.String() == "other_phone" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.Address = val.String()
}
}
}
}
}
}
}
}
// extract websites and social links
if val.String() == "websites_and_social_links" {
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
val, ok := node.Object()["field_type"]
if !ok {
continue
}
// extract website
if val.String() == "website" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.Websites = append(contactBasic.Websites, val.String())
}
}
}
// extract social link
if val.String() == "screenname" {
socialLink := SocialLink{}
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
socialLink.URLOrScreenname = val.String()
}
}
// extract social media name
if val, ok := node.Object()["list_item_groups"]; ok {
for _, group := range val.Array() {
if val, ok := group.Object()["list_items"]; ok {
for _, item := range val.Array() {
if val, ok := item.Object()["text"]; ok {
socialLink.Type = val.Object()["text"].String()
}
}
}
}
}
contactBasic.SocialLinks = append(contactBasic.SocialLinks, socialLink)
}
}
}
}
}
// extract basic infos
if val.String() == "basic_info" {
contactBasic.BasicInfo = new(BasicInfo)
if val, ok := section.Object()["profile_fields"]; ok {
if val, ok := val.Object()["nodes"]; ok {
for _, node := range val.Array() {
val, ok := node.Object()["field_type"]
if !ok {
continue
}
// extract gender
if val.String() == "gender" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.BasicInfo.Gender = strings.ToUpper(val.String())
}
}
}
// extract birthday
if val.String() == "birthday" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
if contactBasic.BasicInfo.Birthday != "" {
contactBasic.BasicInfo.Birthday += ", "
}
contactBasic.BasicInfo.Birthday += val.String()
}
}
}
// extract languages
if val.String() == "languages" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.BasicInfo.Languages = val.String()
}
}
}
// extract relion views
if val.String() == "religion" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.BasicInfo.ReligiousViews = val.String()
}
}
}
// extract political views
if val.String() == "politics" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.BasicInfo.PoliticalViews = val.String()
}
}
}
// extract interested in
if val.String() == "interested_in" {
if val, ok := node.Object()["title"]; ok {
if val, ok := val.Object()["text"]; ok {
contactBasic.BasicInfo.InterestedIn = strings.ToUpper(val.String())
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return contactBasic
}