add subcommand 'following'

This commit is contained in:
gutmet 2020-10-23 19:54:15 +02:00
parent a39bdae46b
commit 268bc13b79
3 changed files with 50 additions and 0 deletions

View File

@ -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):
```

View File

@ -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)

View File

@ -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
}