From b3b14e615e6088322875964cc4707982b12d109d Mon Sep 17 00:00:00 2001 From: gutmet Date: Sat, 19 Sep 2020 22:31:09 +0200 Subject: [PATCH] new retweet subcommand --- Readme.md | 16 +++++++++++----- drivel.go | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 334b649..aa0580d 100644 --- a/Readme.md +++ b/Readme.md @@ -2,7 +2,7 @@ drivel ======== drivel is a Twitter command line interface for status updates, media upload, -your home timeline, your mention timeline, replies, quotes and likes. +your home timeline, your mention timeline, replies, quotes, retweets and likes. My personal opinion is that you shouldn't be on Twitter in the first place, but anyway... @@ -40,21 +40,27 @@ To like a tweet with a specific ID: drivel like TWEET_ID ``` -To update your status with optional media upload... +To retweet a tweet with a specific ID: + +``` +drivel retweet TWEET_ID +``` + +To update your status with optional media upload: ``` drivel status STATUS [FILE1, FILE2, ...] ``` -...reply to a tweet with a specific ID... +To reply to a tweet with a specific ID: ``` drivel reply TWEET_ID MESSAGE [FILE1, FILE2, ...] ``` -...or quote a tweet with a specific ID... +To quote a tweet with a specific ID: ``` drivel quote TWEET_ID MESSAGE [FILE1, FILE2, ...] @@ -112,4 +118,4 @@ with id 1013200061533171712 final note ---------- -You can buy me a beer [here](http://paypal.me/AlexanderWeinhold). \ No newline at end of file +You can buy me a beer [here](http://paypal.me/AlexanderWeinhold). diff --git a/drivel.go b/drivel.go index 5f32c99..d148105 100644 --- a/drivel.go +++ b/drivel.go @@ -25,6 +25,7 @@ const ( 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" 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" ) @@ -479,7 +480,6 @@ func updateStatus(args []string, previous ObjectID, embedTweet ObjectID) { d.status[0] += " " + tweets[0].URL() } } - d.push(httpClient, previous) } @@ -557,6 +557,30 @@ func home(args []string) error { return nil } +func RetweetParameters(id string) string { + return id + ".json" +} + +func retweet(args []string) error { + log := func(err error) { optLogFatal("retweet", err) } + if len(args) != 1 { + fmt.Fprintln(os.Stderr, "USAGE: drivel retweet TWEET_ID") + os.Exit(-1) + } + client := getClient() + id := args[0] + tweets := lookup(client, []string{id}) + if len(tweets) != 1 { + log(errors.New("Could not find tweet " + id)) + } + body := send(client, RETWEET_ENDPOINT+RetweetParameters(id), nil) + var retweet Status + err := json.Unmarshal(body, &retweet) + log(err) + fmt.Println("Retweeted", tweets[0]) + return nil +} + func LikeRequest(id string) url.Values { return map[string][]string{ "id": {id}, @@ -586,6 +610,7 @@ func main() { goutil.NewCommand("mentions", mentions, "get your mention timeline"), goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"), goutil.NewCommand("quote", quote, "quote retweet a tweet with a specific ID"), + goutil.NewCommand("retweet", retweet, "retweet a tweet with a specific ID"), goutil.NewCommand("like", like, "like a tweet with a specific ID"), } err := goutil.Execute(commands)