Skip to content

Commit

Permalink
Merge pull request #11 from bogosj/option3
Browse files Browse the repository at this point in the history
Add support for multiple IDs.
  • Loading branch information
jadametz authored Nov 17, 2020
2 parents 0484ad4 + 5d67be0 commit 13930a2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following environment variables exist for configuration:
|`CONSUMERKEY`|Twitter API credential|Y||
|`CONSUMERSECRET`|Twitter API credential|Y||
|`DAYSTOKEEP`|The number of days to keep Tweets before they're deleted|N|`30`|
|`IGNOREID`|The Tweet ID of a Tweet you'd like to be ignored (e.g. a pinned Tweet)|N||
|`IGNOREIDS`|The Tweet ID(s), comma separated, of a Tweet you'd like to be ignored (e.g. a pinned Tweet)|N||
|`INCLUDERETWEETS`|Whether RT's should be included in the search/deletion|N|`true`|
|`SCREENNAME`|Your Twitter handle|Y||

Expand Down
11 changes: 10 additions & 1 deletion config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ type Config struct {
ConsumerKey string `required:"true"`
ConsumerSecret string `required:"true"`
DaysToKeep int `default:"30"`
IgnoreID int64
IgnoreIDs []int64
IncludeRetweets bool `default:"true"`
ScreenName string `required:"true"`
}

func (c *Config) ShouldIgnoreId(id int64) bool {
for _, i := range c.IgnoreIDs {
if i == id {
return true
}
}
return false
}

// New returns a new Config struct
func New() (*Config, error) {
var c Config
Expand Down
59 changes: 59 additions & 0 deletions config/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package config

import "testing"

func TestConfig_ShouldIgnoreId(t *testing.T) {
type fields struct {
IgnoreIDs []int64
}
type args struct {
id int64
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "One ID provided and found",
fields: fields{IgnoreIDs: []int64{123}},
args: args{id: int64(123)},
want: true,
},
{
name: "One ID provided but not found",
fields: fields{IgnoreIDs: []int64{123}},
args: args{id: int64(321)},
want: false,
},
{
name: "Multiple IDs provided but not found",
fields: fields{IgnoreIDs: []int64{123, 456}},
args: args{id: int64(321)},
want: false,
},
{
name: "Multiple IDs provided and one found",
fields: fields{IgnoreIDs: []int64{123, 456}},
args: args{id: int64(456)},
want: true,
},
{
name: "No IDs provided",
fields: fields{IgnoreIDs: nil},
args: args{id: int64(456)},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
IgnoreIDs: tt.fields.IgnoreIDs,
}
if got := c.ShouldIgnoreId(tt.args.id); got != tt.want {
t.Errorf("Config.ShouldIgnoreId() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion twitter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (t *Twitter) DeleteOldTweets() (deleted, ignored, skipped int, err error) {
}

for _, tweet := range allTweets {
if tweet.ID == t.Config.IgnoreID {
if t.Config.ShouldIgnoreId(tweet.ID) {
ignored++
continue
}
Expand Down

0 comments on commit 13930a2

Please sign in to comment.