1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
Casey Primozic 4c9990bafd
Implement initial twitterstats module
* Create module skeleton based off of the existing twitter module
  * Strip out unused pieces and try to make it as minimal as possible
 * Implement settings parsing, converting the untyped `screenNames` slice into an slice of strings
 * Implement initial minimal display, showing a table with all usernames and their follower count + # of tweets (using dummy metrics for now)
2019-10-22 11:58:20 -07:00

59 lines
1.2 KiB
Go

package twitterstats
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/view"
)
type Widget struct {
view.KeyboardWidget
view.TextWidget
client *Client
idx int
settings *Settings
sources []string
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
TextWidget: view.NewTextWidget(app, settings.common),
idx: 0,
settings: settings,
}
widget.client = NewClient(settings)
widget.View.SetBorderPadding(1, 1, 1, 1)
widget.View.SetWrap(true)
widget.View.SetWordWrap(true)
return &widget
}
func (widget *Widget) Refresh() {
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
usernames := widget.client.screenNames
followerCounts := widget.client.GetFollowerCounts()
tweetCounts := widget.client.GetTweetCounts()
// Add header row
str := fmt.Sprintf("%-16s %-8s %-8s\n", "Username", "Followers", "# Tweets")
// Add rows for each of the followed usernames
for i, username := range usernames {
followerCount := followerCounts[i]
tweetCount := tweetCounts[i]
str += fmt.Sprintf("%-16s %8d %8d\n", username, followerCount, tweetCount)
}
return "Twitter Stats", str, true
}