Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add support for dynamic followings lookup
Browse files Browse the repository at this point in the history
This change introduces dynamic followings lookup in case no IG usernames
are provided.
  • Loading branch information
falzm committed Jun 11, 2020
1 parent cf4456f commit 8fbc508
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 22 additions & 4 deletions instafeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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/"},
Expand Down

0 comments on commit 8fbc508

Please sign in to comment.