This repository was archived by the owner on Mar 18, 2018. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414.glide /
1515
1616# Build
17- instago
17+ main
1818dist /
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ package main
22
33import (
44 "flag"
5+ "fmt"
56 "log"
67 "os"
78 "time"
89
910 "github.com/araddon/dateparse"
11+ "github.com/pagumin/instago/pkg/instago"
1012 "github.com/pagumin/instago/pkg/utilities"
1113)
1214
@@ -92,8 +94,29 @@ func main() {
9294
9395 // GET THE POSTS
9496
97+ log .Printf ("searching for %s" , user )
98+
99+ data := make (chan instago.Instagram )
100+ err := make (chan error )
101+ go instago .Retrieve (user , data , err )
102+
103+ for i := 0 ; i < 1 ; i ++ {
104+
105+ select {
106+ case e := <- err :
107+ fmt .Println (e )
108+ case d := <- data :
109+ for _ , post := range d .Items {
110+ log .Println (post .ID )
111+ }
112+ }
113+
114+ }
115+
95116 // FILTER THE POSTS
96117
97118 // DOWNLOAD THE FILTERED POSTS
98119
120+ return
121+
99122}
Original file line number Diff line number Diff line change 1+ package instago
2+
3+ func (i Instagram ) parse () (posts []post ) {
4+
5+ for _ , single := range i .Items {
6+
7+ temp := post {
8+ ID : single .ID ,
9+ Created : single .CreatedTime ,
10+ Caption : single .Caption .Text ,
11+ Likes : single .Likes .Count ,
12+ Comments : single .Comments .Count ,
13+ Location : single .Location .Name ,
14+ }
15+
16+ carousel := single .CarouselMedia
17+
18+ if len (carousel ) > 0 {
19+
20+ for _ , seat := range carousel {
21+
22+ t := solve (seat .Images .StandardResolution .URL , seat .Videos .StandardResolution .URL )
23+ temp .Media = append (temp .Media , t )
24+
25+ }
26+
27+ } else {
28+
29+ t := solve (single .Images .StandardResolution .URL , single .Videos .StandardResolution .URL )
30+ temp .Media = append (temp .Media , t )
31+
32+ }
33+
34+ posts = append (posts , temp )
35+
36+ }
37+
38+ return
39+
40+ }
41+
42+ func solve (picture , video string ) postmedia {
43+
44+ var url string
45+ var vid bool
46+
47+ switch {
48+ case video != "" :
49+ url = video
50+ vid = true
51+ default :
52+ url = picture
53+ }
54+
55+ t := postmedia {
56+ URL : url ,
57+ Video : vid ,
58+ }
59+
60+ return t
61+
62+ }
Original file line number Diff line number Diff line change 1+ package instago
2+
3+ import (
4+ "encoding/json"
5+ "net/http"
6+ )
7+
8+ // Retrieve will return the data from the user
9+ func Retrieve (user string , data chan Instagram , err chan error ) {
10+
11+ url := "https://www.instagram.com/" + user + "/media/"
12+
13+ d , e := fetch (url )
14+ if e != nil {
15+ err <- e
16+ return
17+ }
18+
19+ data <- d
20+
21+ return
22+ }
23+
24+ func fetch (url string ) (data Instagram , err error ) {
25+
26+ res , err := http .Get (url )
27+ if err != nil {
28+ return
29+ }
30+
31+ err = json .NewDecoder (res .Body ).Decode (& data )
32+ if err != nil {
33+ return
34+ }
35+
36+ res .Body .Close ()
37+
38+ return
39+ }
40+
41+ // // Retrieve gets all of the information about a user.
42+ // func Retrieve(user string, id string, data chan instagram) {
43+
44+ // url := "https://www.instagram.com/" + user + "/media/"
45+
46+ // if id != "" {
47+
48+ // url = url + "?max_id=" + id
49+ // }
50+
51+ // res, err := http.Get(url)
52+ // if err != nil {
53+ // log.Fatal(err)
54+ // }
55+
56+ // res.Body.Close()
57+
58+ // }
59+
60+ // func retrieve(u string) {
61+
62+ // res, err := http.Get(u)
63+ // if err != nil {
64+ // log.Println(err)
65+ // return
66+ // }
67+
68+ // var j instagram
69+ // if err := json.NewDecoder(res.Body).Decode(&j); err != nil {
70+ // log.Fatal(err)
71+ // return
72+ // }
73+
74+ // res.Body.Close()
75+
76+ // if len(j.Items) < 1 {
77+ // log.Println("user is private or does not exist.")
78+ // return
79+ // }
80+
81+ // if j.MoreAvailable {
82+ // id := j.Items[len(j.Items)-1].ID
83+ // u := "https://www.instagram.com/" + user + "/media/?max_id=" + id
84+ // retrieve(u)
85+ // }
86+
87+ // j.parse()
88+
89+ // }
Original file line number Diff line number Diff line change 1+ package instago
2+
3+ // func (m media) save() error {
4+
5+ // url := m.Video
6+
7+ // if url == "" && vids {
8+ // return nil
9+ // }
10+
11+ // if url == "" || pics {
12+ // url = m.Image
13+ // url = strings.Replace(url, "s640x640", "s1080x1080", -1)
14+ // }
15+
16+ // d := filepath.Join(dir, user)
17+
18+ // if _, err := os.Stat(d); os.IsNotExist(err) {
19+ // if err := os.Mkdir(d, 0755); err != nil {
20+ // log.Fatal(err)
21+ // return err
22+ // }
23+ // }
24+
25+ // _, name := filepath.Split(url)
26+ // newPath := filepath.Join(d, name)
27+
28+ // if _, err := os.Stat(newPath); !os.IsNotExist(err) && !skip {
29+ // log.Printf("%s has already been saved. skipping....\n", name)
30+ // return nil
31+ // }
32+
33+ // res, err := http.Get(url)
34+ // if err != nil {
35+ // return err
36+ // }
37+
38+ // defer res.Body.Close()
39+
40+ // file, err := os.Create(newPath)
41+ // if err != nil {
42+ // log.Fatal(err)
43+ // return err
44+ // }
45+
46+ // defer file.Close()
47+
48+ // if _, err := io.Copy(file, res.Body); err != nil {
49+ // log.Fatal(err)
50+ // return err
51+ // }
52+
53+ // log.Printf("successfully downloaded %s\n", name)
54+ // return nil
55+
56+ // }
You can’t perform that action at this time.
0 commit comments