new like subcommand

This commit is contained in:
gutmet 2020-09-18 09:18:32 +02:00
parent f32dc1b3c5
commit d9c5c24689
2 changed files with 32 additions and 1 deletions

View File

@ -1,7 +1,8 @@
drivel drivel
======== ========
drivel is a Twitter command line interface for status updates, media upload, your home timeline, your mention timeline and replies. drivel is a Twitter command line interface for status updates, media upload,
your home timeline, your mention timeline, replies and likes.
My personal opinion is that you shouldn't be on Twitter in the first place, but My personal opinion is that you shouldn't be on Twitter in the first place, but
anyway... anyway...
@ -33,6 +34,12 @@ To get the last 200 tweets of your mention timeline:
drivel mentions drivel mentions
``` ```
To like a tweet with a specific ID:
```
drivel like TWEET_ID
```
To update your status with optional media upload... To update your status with optional media upload...

View File

@ -22,6 +22,7 @@ const (
STATUS_ENDPOINT = "https://api.twitter.com/1.1/statuses/update.json" STATUS_ENDPOINT = "https://api.twitter.com/1.1/statuses/update.json"
MENTIONS_ENDPOINT = "https://api.twitter.com/1.1/statuses/mentions_timeline.json?tweet_mode=extended&count=200" MENTIONS_ENDPOINT = "https://api.twitter.com/1.1/statuses/mentions_timeline.json?tweet_mode=extended&count=200"
HOME_ENDPOINT = "https://api.twitter.com/1.1/statuses/home_timeline.json?tweet_mode=extended&count=200" HOME_ENDPOINT = "https://api.twitter.com/1.1/statuses/home_timeline.json?tweet_mode=extended&count=200"
LIKE_ENDPOINT = "https://api.twitter.com/1.1/favorites/create.json"
) )
func optLogFatal(decorum string, err error) { func optLogFatal(decorum string, err error) {
@ -416,12 +417,35 @@ func home(args []string) error {
return nil return nil
} }
func LikeRequest(id string) url.Values {
return map[string][]string{
"id": {id},
"tweet_mode": {"extended"},
}
}
func like(args []string) error {
log := func(err error) { optLogFatal("like", err) }
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "USAGE: drivel like TWEET_ID")
os.Exit(-1)
}
client := getClient()
body := send(client, LIKE_ENDPOINT, LikeRequest(args[0]))
var tweet Status
err := json.Unmarshal(body, &tweet)
log(err)
fmt.Println("Liked", tweet)
return nil
}
func main() { func main() {
commands := []goutil.Command{ commands := []goutil.Command{
goutil.NewCommand("status", status, "post a status with message and/or media"), goutil.NewCommand("status", status, "post a status with message and/or media"),
goutil.NewCommand("home", home, "get your home timeline"), goutil.NewCommand("home", home, "get your home timeline"),
goutil.NewCommand("mentions", mentions, "get your mention timeline"), goutil.NewCommand("mentions", mentions, "get your mention timeline"),
goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"), goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"),
goutil.NewCommand("like", like, "like a tweet with a specific ID"),
} }
err := goutil.Execute(commands) err := goutil.Execute(commands)
if err != nil { if err != nil {