diff --git a/README.md b/README.md index ac6ef6c..919efe7 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,12 @@ At the top of the sources directory, just type `make`. If everything went well, Run `instafeed -h` for usage help. -`instafeed` expects the `IG_LOGIN` and `IG_PASSWORD` environment variables set to your Instagram login and password respectively, and the username of the Instagram user provided as argument. On successful execution, it prints the resulting RSS feed on the standard output. +`instafeed` expects the `IG_LOGIN` and `IG_PASSWORD` environment variables set to your Instagram login and password respectively, and optionally the username of the Instagram user provided as argument. On successful execution, it prints the resulting RSS feed on the standard output. If multiple Instagram users arguments are provided, `instafeed` will bulk all retrieved posts into a single feed sorted in reverse chronological order (i.e. from newest to oldest). +If no Instagram usernames are provided – either as command line arguments or via the `-l` option –, `instafeed` attempts to retrieve the currently logged account's *followings* and use those as the source of usernames. + Example: ```console diff --git a/instafeed.go b/instafeed.go index ca5fd85..84b3cd1 100644 --- a/instafeed.go +++ b/instafeed.go @@ -64,10 +64,6 @@ func main() { } } - if len(igUsers) == 0 && len(flag.Args()) == 0 { - dieOnError("missing Instagram username argument") - } - igLogin := os.Getenv("IG_LOGIN") igPassword := os.Getenv("IG_PASSWORD") @@ -89,6 +85,28 @@ func main() { fmt.Fprintf(os.Stderr, "error: unable to export Instagram client configuration: %s\n", err) } + if len(igUsers) == 0 { + // If no static list of IG users is provided, attempt retrieving the list of followings + // from the logged user's account + for followings := insta.Account.Following(); followings.Next(); { + for _, u := range followings.Users { + igUsers = append(igUsers, u.Username) + } + + if err := followings.Error(); err != nil { + if err == goinsta.ErrNoMore { + break + } + + dieOnError("unable to retrieve followings: %s", err) + } + } + + if len(igUsers) == 0 { + dieOnError("no users provided") + } + } + feed := &feeds.Feed{ Title: fmt.Sprintf("Instagram"), Link: &feeds.Link{Href: "https://www.instagram.com/"},