Skip to content

Commit

Permalink
feat: integrate with spf13/cobra
Browse files Browse the repository at this point in the history
resolves #7
  • Loading branch information
cecobask committed Oct 2, 2023
1 parent 91ffb02 commit ce7bea6
Show file tree
Hide file tree
Showing 113 changed files with 14,413 additions and 1,018 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/findUnfollowers.yaml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/unfollowers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: unfollowers
on:
push:
branches:
- main
workflow_dispatch:

env:
ARCHIVE_URL: ${{ secrets.ARCHIVE_URL }}

jobs:
findUnfollowers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.21'
cache: true
- name: Download instagram information locally
run: go run main.go information download $ARCHIVE_URL
- name: Find out which instagram users are not following back
run: go run main.go followdata unfollowers
- name: Cleanup local instagram information
run: go run main.go information cleanup
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
.DS_Store
.idea
.env
instagram_data.zip
instagram_data
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ Find out which users are not following you back.
- Upload the zip file to Google Drive
- File access: `Anyone with link`
- Fetch the file url: `Copy link`
- Copy the file id
The URL format is https://drive.google.com/file/d/xxxyyyzzz/view. In this case `xxxyyyzzz` is the file id...
- Set up your repository
- Fork the [cecobask/instagram-unfollowers](https://github.com/cecobask/instagram-unfollowers) to your account
- Enable the `findUnfollowers` workflow ([help](https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow))
- Create a repository secret with name `FILE_ID` and value equal to the Google Drive file id ([help](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository))
- Run the `findUnfollowers` workflow ([help](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow))
- Enable the `unfollowers` workflow ([help](https://docs.github.com/en/actions/using-workflows/disabling-and-enabling-a-workflow))
- Create a repository secret with name `ARCHIVE_URL` and value equal to the Google Drive file url ([help](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository))
- Run the `unfollowers` workflow ([help](https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow))
- Shortly, check the console output of the job
- If any users are not following back, you will see info about them in table format

Expand All @@ -25,4 +23,4 @@ You can proceed as follows:
- Download your information from Instagram
- Find your previously uploaded file on Google Drive
- Upload a new version by clicking `Manage versions`
- Run the `findUnfollowers` workflow
- Run the `unfollowers` workflow
17 changes: 17 additions & 0 deletions cmd/followdata/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package followdata

import (
"github.com/spf13/cobra"
)

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "followdata",
Short: "Various instagram follow information operations",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(NewUnfollowersCommand())
return cmd
}
25 changes: 25 additions & 0 deletions cmd/followdata/unfollowers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package followdata

import (
"github.com/cecobask/instagram-unfollowers/pkg/instagram"
"github.com/spf13/cobra"
)

func NewUnfollowersCommand() *cobra.Command {
return &cobra.Command{
Use: "unfollowers",
Short: "Find out which instagram users are not following back",
RunE: func(cmd *cobra.Command, args []string) error {
return run()
},
}
}

func run() error {
followData := instagram.NewFollowData()
if err := followData.ExtractAllData(); err != nil {
return err
}
followData.FindUnfollowers()
return nil
}
22 changes: 22 additions & 0 deletions cmd/information/cleanup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package information

import (
"fmt"
"github.com/cecobask/instagram-unfollowers/pkg/instagram"
"github.com/spf13/cobra"
)

func NewCleanupCommand() *cobra.Command {
return &cobra.Command{
Use: "cleanup",
Short: "Cleanup local instagram information",
RunE: func(cmd *cobra.Command, args []string) error {
err := instagram.CleanupInstagramInformation()
if err != nil {
return err
}
fmt.Println("cleaned up local instagram information")
return nil
},
}
}
28 changes: 28 additions & 0 deletions cmd/information/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package information

import (
"fmt"
"github.com/cecobask/instagram-unfollowers/pkg/instagram"
"github.com/spf13/cobra"
)

func NewDownloadCommand() *cobra.Command {
return &cobra.Command{
Use: "download <url>",
Short: "Download instagram information locally",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("must provide exactly one archive download url")
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
err := instagram.FetchInstagramInformation(args[0])
if err != nil {
return err
}
fmt.Println("downloaded instagram information locally")
return nil
},
}
}
20 changes: 20 additions & 0 deletions cmd/information/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package information

import "github.com/spf13/cobra"

type Options struct {
ArchiveDownloadURL string
}

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "information",
Short: "Instagram information operations",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(NewDownloadCommand())
cmd.AddCommand(NewCleanupCommand())
return cmd
}
24 changes: 24 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package root

import (
"github.com/cecobask/instagram-unfollowers/cmd/followdata"
"github.com/cecobask/instagram-unfollowers/cmd/information"
"github.com/spf13/cobra"
)

func NewRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "instagram",
Short: "Instagram operations",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
SilenceUsage: true,
}
cmd.AddCommand(information.NewRootCommand())
cmd.AddCommand(followdata.NewRootCommand())
return cmd
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module github.com/cecobask/instagram-unfollowers

go 1.20
go 1.21

require (
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/joho/godotenv v1.5.1
github.com/jedib0t/go-pretty/v6 v6.4.7
github.com/spf13/cobra v1.7.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.1.0 // indirect
)
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1Rjl9Jw=
github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.4.7 h1:lwiTJr1DEkAgzljsUsORmWsVn5MQjt1BPJdPCtJ6KXE=
github.com/jedib0t/go-pretty/v6 v6.4.7/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
Loading

0 comments on commit ce7bea6

Please sign in to comment.