-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
70 lines (64 loc) · 1.4 KB
/
profile.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
package main
import (
"encoding/json"
"fmt"
"math/rand"
)
const profileUrl = "https://www.instagram.com/%s"
var randomProfiles = []string{
"asianhotgirlsdaily",
"asian_girls_cuties",
"vnsexy.collection",
"vietnamesexybabe",
"elly_yj",
"tyty__angel",
"iamnhilolo_",
"linhcandy12",
"anlee.9x",
"taotao1441",
"ellabae_21",
"amy.nguyen97",
"lalinbaby_",
"pongkyubi",
"thaotran2296",
}
type InstagProfileResponse struct {
EntryData struct {
ProfilePage []struct {
Graphql struct {
User struct {
EdgeOwnerToTimelineMedia struct {
Edges []Edge `json:"edges"`
} `json:"edge_owner_to_timeline_media"`
} `json:"user"`
} `json:"graphql"`
} `json:"ProfilePage"`
} `json:"entry_data"`
}
func GetRandomFromProfile() (string, error) {
profile := randomProfiles[rand.Intn(len(randomProfiles))]
return GetFromProfile(profile)
}
func GetFromProfile(profile string) (string, error) {
url := fmt.Sprintf(profileUrl, profile)
response, err := Get(url)
if err != nil {
return "", err
}
response, err = ExtractJson(response)
if err != nil {
return "", err
}
result := &InstagProfileResponse{}
err = json.Unmarshal(response, result)
if err != nil {
return "", err
}
edges := result.EntryData.ProfilePage[0].Graphql.User.EdgeOwnerToTimelineMedia.Edges
max := len(edges)
if max > 100 {
max = 100
}
randomEdge := edges[rand.Intn(max)]
return randomEdge.Node.DisplayUrl, nil
}