1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
Casey Primozic 0be63a404c
Implement Twitter API fetching for twitterstats
* Create Oauth2 client configured for Twitter and create a HTTP client out of that
 * Fetch user stats for each of the users, parse out of JSON, and return stats as stats structs
2019-10-22 12:42:11 -07:00

58 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
stats := widget.client.GetStats()
// 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 := stats[i].followerCount
tweetCount := stats[i].tweetCount
str += fmt.Sprintf("%-16s %8d %8d\n", username, followerCount, tweetCount)
}
return "Twitter Stats", str, true
}