From 268bc13b792c7be2175b3a25e5ee4cf658788c6b Mon Sep 17 00:00:00 2001 From: gutmet Date: Fri, 23 Oct 2020 19:54:15 +0200 Subject: [PATCH] add subcommand 'following' --- Readme.md | 6 ++++++ drivel.go | 34 ++++++++++++++++++++++++++++++++++ requests.go | 10 ++++++++++ 3 files changed, 50 insertions(+) diff --git a/Readme.md b/Readme.md index c553482..524b362 100644 --- a/Readme.md +++ b/Readme.md @@ -55,6 +55,12 @@ To lookup tweets with specific IDs: drivel lookup TWEET_ID1 [TWEET_ID2 TWEET_ID3 ...] ``` +To get a list of the people you follow: + +``` +drivel following +``` + To wipe your timeline and likes (keepDays defaults to 10, can only reach back as far as the result of the timeline): ``` diff --git a/drivel.go b/drivel.go index 78a82d7..8ece7a3 100644 --- a/drivel.go +++ b/drivel.go @@ -32,6 +32,7 @@ const ( LOOKUP_ENDPOINT = "https://api.twitter.com/1.1/statuses/lookup.json?tweet_mode=extended" RETWEET_ENDPOINT = "https://api.twitter.com/1.1/statuses/retweet/" LIKE_ENDPOINT = "https://api.twitter.com/1.1/favorites/create.json" + FOLLOWING_ENDPOINT = "https://api.twitter.com/1.1/friends/list.json?count=200" DESTROY_STATUS_ENDPOINT = "https://api.twitter.com/1.1/statuses/destroy/" DESTROY_LIKE_ENDPOINT = "https://api.twitter.com/1.1/favorites/destroy.json" ) @@ -418,6 +419,38 @@ func like(args []string) error { return nil } +func _following() (following hashset) { + log := func(err error) { optLogFatal("following", err) } + following = makeHashset() + defer func() { + if r := recover(); r != nil { + fmt.Fprintln(os.Stderr, r) + } + }() + var cursor int64 = -1 + var err error + for cursor != 0 && err == nil { + body := get(FOLLOWING_ENDPOINT + FollowingParameters(cursor)) + var response FollowingResponse + err = json.Unmarshal(body, &response) + log(err) + for _, user := range response.Users { + following.add(user.Screen_name) + } + cursor = response.Next_cursor + } + return +} + +func following(args []string) error { + checkUsage(args, 0, 0, "following") + set := _following() + for user, _ := range set { + fmt.Println(user) + } + return nil +} + func unlike(id string) { log := func(err error) { optLogFatal("unlike", err) } body := post(DESTROY_LIKE_ENDPOINT, UnlikeRequest(id)) @@ -579,6 +612,7 @@ func main() { goutil.NewCommandWithFlags("quote", wrapCommand(quote), "quote retweet a tweet with a specific ID"), goutil.NewCommandWithFlags("retweet", wrapCommand(retweet), "retweet a tweet with a specific ID"), goutil.NewCommandWithFlags("like", wrapCommand(like), "like a tweet with a specific ID"), + goutil.NewCommand("following", following, "try to get the list of users you are following"), goutil.NewCommandWithFlags("wipe", wipeCommand, "wipe your timeline and likes"), } _ = goutil.Execute(commands) diff --git a/requests.go b/requests.go index f14039d..671a038 100644 --- a/requests.go +++ b/requests.go @@ -2,6 +2,7 @@ package main import ( "net/url" + "strconv" "strings" ) @@ -58,3 +59,12 @@ func UnlikeRequest(id string) url.Values { func DestroyParameters(id string) string { return id + ".json?tweet_mode=extended" } + +func FollowingParameters(cursor int64) string { + return "&skip_status=true&include_user_entities=false&cursor=" + strconv.FormatInt(cursor, 10) +} + +type FollowingResponse struct { + Users []StatusUser + Next_cursor int64 +}