home timeline functionality
This commit is contained in:
parent
cea0ee0938
commit
84e0b08eae
10
Readme.md
10
Readme.md
|
@ -1,7 +1,7 @@
|
|||
drivel
|
||||
========
|
||||
|
||||
drivel is a Twitter command line interface for status updates, media upload, mentions and replies.
|
||||
drivel is a Twitter command line interface for status updates, media upload, your home timeline, your mention timeline and replies.
|
||||
My personal opinion is that you shouldn't be on Twitter in the first place, but
|
||||
anyway...
|
||||
|
||||
|
@ -21,7 +21,13 @@ go build drivel.go credentials.go
|
|||
usage
|
||||
-----
|
||||
|
||||
To get your last 100 mentions:
|
||||
To get the last 100 tweets of your home timeline:
|
||||
|
||||
```
|
||||
drivel home
|
||||
```
|
||||
|
||||
To get the last 100 tweets of your mention timeline:
|
||||
|
||||
```
|
||||
drivel mentions
|
||||
|
|
69
drivel.go
69
drivel.go
|
@ -21,6 +21,7 @@ const (
|
|||
UPLOAD_ENDPOINT = "https://upload.twitter.com/1.1/media/upload.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=100"
|
||||
HOME_ENDPOINT = "https://api.twitter.com/1.1/statuses/home_timeline.json?tweet_mode=extended&count=100"
|
||||
)
|
||||
|
||||
func optLogFatal(decorum string, err error) {
|
||||
|
@ -369,34 +370,6 @@ func status(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type Mention struct {
|
||||
Full_text string
|
||||
Id_str string
|
||||
User MentionUser
|
||||
}
|
||||
|
||||
func (m Mention) String() string {
|
||||
return m.User.Name + " " + "(" + m.Id_str + ")" + ":\n" + m.Full_text
|
||||
}
|
||||
|
||||
type MentionUser struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func mentions(args []string) error {
|
||||
log := func(err error) { optLogFatal("mentions", err) }
|
||||
client := getClient()
|
||||
body := get(client, MENTIONS_ENDPOINT)
|
||||
var mentions []Mention
|
||||
err := json.Unmarshal(body, &mentions)
|
||||
log(err)
|
||||
for _, mention := range mentions {
|
||||
fmt.Println(mention)
|
||||
fmt.Println("---------")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func reply(args []string) error {
|
||||
if len(args) < 2 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: drivel reply TWEET_ID MESSAGE [FILE1, FILE2, ...]")
|
||||
|
@ -406,10 +379,48 @@ func reply(args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type Status struct {
|
||||
Full_text string
|
||||
Id_str string
|
||||
User StatusUser
|
||||
}
|
||||
|
||||
func (m Status) String() string {
|
||||
return m.User.Name + " " + "(" + m.Id_str + ")" + ":\n" + m.Full_text
|
||||
}
|
||||
|
||||
type StatusUser struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func timeline(endpoint string) {
|
||||
log := func(err error) { optLogFatal("timeline", err) }
|
||||
client := getClient()
|
||||
body := get(client, endpoint)
|
||||
var tweets []Status
|
||||
err := json.Unmarshal(body, &tweets)
|
||||
log(err)
|
||||
for _, tweet := range tweets {
|
||||
fmt.Println(tweet)
|
||||
fmt.Println("---------")
|
||||
}
|
||||
}
|
||||
|
||||
func mentions(args []string) error {
|
||||
timeline(MENTIONS_ENDPOINT)
|
||||
return nil
|
||||
}
|
||||
|
||||
func home(args []string) error {
|
||||
timeline(HOME_ENDPOINT)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
commands := []goutil.Command{
|
||||
goutil.NewCommand("status", status, "post a status with message and/or media"),
|
||||
goutil.NewCommand("mentions", mentions, "get your mentions"),
|
||||
goutil.NewCommand("home", home, "get your home timeline"),
|
||||
goutil.NewCommand("mentions", mentions, "get your mention timeline"),
|
||||
goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"),
|
||||
}
|
||||
err := goutil.Execute(commands)
|
||||
|
|
Loading…
Reference in New Issue
Block a user