@@ -3,6 +3,8 @@ package main
33import (
44 "net/url"
55 "os"
6+ "strconv"
7+ "strings"
68 "time"
79
810 "log"
1719 accessToken = getenv ("TWITTER_ACCESS_TOKEN" )
1820 accessTokenSecret = getenv ("TWITTER_ACCESS_TOKEN_SECRET" )
1921 maxTweetAge = getenv ("MAX_TWEET_AGE" )
22+ whitelist = getWhitelist ()
2023)
2124
2225func getenv (name string ) string {
@@ -27,6 +30,16 @@ func getenv(name string) string {
2730 return v
2831}
2932
33+ func getWhitelist () []string {
34+ v := os .Getenv ("WHITELIST" )
35+
36+ if v == "" {
37+ return make ([]string , 0 )
38+ }
39+
40+ return strings .Split (v , ":" )
41+ }
42+
3043func getTimeline (api * anaconda.TwitterApi ) ([]anaconda.Tweet , error ) {
3144 args := url.Values {}
3245 args .Add ("count" , "200" ) // Twitter only returns most recent 20 tweets by default, so override
@@ -38,6 +51,17 @@ func getTimeline(api *anaconda.TwitterApi) ([]anaconda.Tweet, error) {
3851 return timeline , nil
3952}
4053
54+ func isWhitelisted (id int64 ) bool {
55+ tweetId := strconv .FormatInt (id , 10 )
56+
57+ for _ , w := range whitelist {
58+ if w == tweetId {
59+ return true
60+ }
61+ }
62+ return false
63+ }
64+
4165func deleteFromTimeline (api * anaconda.TwitterApi , ageLimit time.Duration ) {
4266 timeline , err := getTimeline (api )
4367
@@ -49,7 +73,7 @@ func deleteFromTimeline(api *anaconda.TwitterApi, ageLimit time.Duration) {
4973 if err != nil {
5074 log .Print ("could not parse time " , err )
5175 } else {
52- if time .Since (createdTime ) > ageLimit {
76+ if time .Since (createdTime ) > ageLimit && ! isWhitelisted ( t . Id ) {
5377 _ , err := api .DeleteTweet (t .Id , true )
5478 log .Print ("DELETED ID " , t .Id )
5579 log .Print ("TWEET " , createdTime , " - " , t .Text )
0 commit comments