Make String() methods more useful for terminal output
This commit is contained in:
parent
6568259d63
commit
d386ba2cb4
@ -3,6 +3,8 @@ package scraper
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"offline_twitter/terminal_utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_MAX_REPLIES_EAGER_LOAD = 50
|
const DEFAULT_MAX_REPLIES_EAGER_LOAD = 50
|
||||||
@ -29,11 +31,42 @@ type Tweet struct {
|
|||||||
QuotedTweet TweetID
|
QuotedTweet TweetID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (t Tweet) String() string {
|
func (t Tweet) String() string {
|
||||||
return fmt.Sprintf(
|
var author string
|
||||||
`ID %s, User %s: %q (%s). Likes: %d, Retweets: %d, QTs: %d, Replies: %d.
|
if t.User != nil {
|
||||||
Urls: %v Images: %v Mentions: %v Hashtags: %v`,
|
author = fmt.Sprintf("%s\n@%s", t.User.DisplayName, t.User.Handle)
|
||||||
t.ID, t.UserID, t.Text, t.PostedAt, t.NumLikes, t.NumRetweets, t.NumQuoteTweets, t.NumReplies, t.Urls, t.Images, t.Mentions, t.Hashtags)
|
} else {
|
||||||
|
author = "@???"
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := fmt.Sprintf(
|
||||||
|
`%s
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
Replies: %d RT: %d QT: %d Likes: %d
|
||||||
|
`,
|
||||||
|
author,
|
||||||
|
terminal_utils.FormatDate(t.PostedAt),
|
||||||
|
terminal_utils.WrapText(t.Text, 60),
|
||||||
|
t.NumReplies,
|
||||||
|
t.NumRetweets,
|
||||||
|
t.NumQuoteTweets,
|
||||||
|
t.NumLikes,
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(t.Images) > 0 {
|
||||||
|
ret += fmt.Sprintf(terminal_utils.COLOR_GREEN + "images: %d\n" + terminal_utils.COLOR_RESET, len(t.Images))
|
||||||
|
}
|
||||||
|
if len(t.Urls) > 0 {
|
||||||
|
ret += "urls: [\n"
|
||||||
|
for _, url := range(t.Urls) {
|
||||||
|
ret += " " + url + "\n"
|
||||||
|
}
|
||||||
|
ret += "]"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn an APITweet, as returned from the scraper, into a properly structured Tweet object
|
// Turn an APITweet, as returned from the scraper, into a properly structured Tweet object
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"offline_twitter/terminal_utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserID string
|
type UserID string
|
||||||
@ -36,7 +38,37 @@ type User struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u User) String() string {
|
func (u User) String() string {
|
||||||
return fmt.Sprintf("%s (@%s)[%s]: %q", u.DisplayName, u.Handle, u.ID, u.Bio)
|
var verified string
|
||||||
|
if u.IsVerified {
|
||||||
|
verified = "[\u2713]"
|
||||||
|
}
|
||||||
|
ret := fmt.Sprintf(
|
||||||
|
`%s%s
|
||||||
|
@%s
|
||||||
|
%s
|
||||||
|
|
||||||
|
Following: %d Followers: %d
|
||||||
|
|
||||||
|
Joined %s
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
`,
|
||||||
|
u.DisplayName,
|
||||||
|
verified,
|
||||||
|
u.Handle,
|
||||||
|
terminal_utils.WrapText(u.Bio, 60),
|
||||||
|
u.FollowingCount,
|
||||||
|
u.FollowersCount,
|
||||||
|
terminal_utils.FormatDate(u.JoinDate),
|
||||||
|
u.Location,
|
||||||
|
u.Website,
|
||||||
|
)
|
||||||
|
if u.PinnedTweet != nil {
|
||||||
|
ret += "\n" + terminal_utils.WrapText(u.PinnedTweet.Text, 60)
|
||||||
|
} else {
|
||||||
|
println("Pinned tweet id:", u.PinnedTweetID)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn an APIUser, as returned from the scraper, into a properly structured User object
|
// Turn an APIUser, as returned from the scraper, into a properly structured User object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user