Skip to content
This repository was archived by the owner on Jun 15, 2025. It is now read-only.

Commit 862b84d

Browse files
author
Vicky Lai
authored
Merge pull request #3 from sw00/master
Add a way to whitelist tweets
2 parents 17ecbec + 7e1430b commit 862b84d

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

main.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"net/url"
55
"os"
6+
"strconv"
7+
"strings"
68
"time"
79

810
"log"
@@ -17,6 +19,7 @@ var (
1719
accessToken = getenv("TWITTER_ACCESS_TOKEN")
1820
accessTokenSecret = getenv("TWITTER_ACCESS_TOKEN_SECRET")
1921
maxTweetAge = getenv("MAX_TWEET_AGE")
22+
whitelist = getWhitelist()
2023
)
2124

2225
func 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+
3043
func 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+
4165
func 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

Comments
 (0)