Created
December 17, 2017 06:07
-
-
Save peteretelej/bb2d93ffcb6f343ac80476008471665b to your computer and use it in GitHub Desktop.
github followers / following
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"github.com/google/go-github/github" | |
) | |
func main() { | |
client := github.NewClient(nil) | |
opts := &github.ListOptions{} | |
var all []github.User | |
opts.Page = 1 | |
for { | |
users, _, err := client.Users.ListFollowers(context.Background(), "peteretelej", opts) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if len(users) == 0 { | |
break | |
} | |
for _, u := range users { | |
all = append(all, *u) | |
} | |
opts.Page += 1 | |
} | |
fmt.Printf("all: %d", len(all)) | |
dat, err := json.Marshal(all) | |
if err != nil { | |
log.Fatalf("json.Marshal: %v", err) | |
} | |
if err := ioutil.WriteFile("out.json", dat, 0755); err != nil { | |
log.Fatalf("writing file: %v", err) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"github.com/google/go-github/github" | |
) | |
func main() { | |
client := github.NewClient(nil) | |
opts := &github.ListOptions{} | |
var all []github.User | |
opts.Page = 1 | |
for { | |
users, _, err := client.Users.ListFollowing(context.Background(), "peteretelej", opts) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if len(users) == 0 { | |
break | |
} | |
for _, u := range users { | |
all = append(all, *u) | |
} | |
opts.Page += 1 | |
} | |
fmt.Printf("all: %d", len(all)) | |
dat, err := json.Marshal(all) | |
if err != nil { | |
log.Fatalf("json.Marshal: %v", err) | |
} | |
if err := ioutil.WriteFile("out.json", dat, 0755); err != nil { | |
log.Fatalf("writing file: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment