mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
BaseWidget added to start reducing some of the code duplication
This commit is contained in:
parent
a09691c86f
commit
b937d64d75
@ -28,7 +28,11 @@ func NewClient() *Client {
|
|||||||
|
|
||||||
// Away returns a string representation of the people who are out of the office during the defined period
|
// Away returns a string representation of the people who are out of the office during the defined period
|
||||||
func (client *Client) Away(itemType, startDate, endDate string) []Item {
|
func (client *Client) Away(itemType, startDate, endDate string) []Item {
|
||||||
calendar, _ := client.away(startDate, endDate)
|
calendar, err := client.away(startDate, endDate)
|
||||||
|
if err != nil {
|
||||||
|
return []Item{}
|
||||||
|
}
|
||||||
|
|
||||||
items := calendar.ItemsByType(itemType)
|
items := calendar.ItemsByType(itemType)
|
||||||
|
|
||||||
return items
|
return items
|
||||||
@ -49,6 +53,9 @@ func (client *Client) away(startDate, endDate string) (cal Calendar, err error)
|
|||||||
)
|
)
|
||||||
|
|
||||||
data, err := Request(client.apiKey, apiURL)
|
data, err := Request(client.apiKey, apiURL)
|
||||||
|
if err != nil {
|
||||||
|
return cal, err
|
||||||
|
}
|
||||||
err = xml.Unmarshal(data, &cal)
|
err = xml.Unmarshal(data, &cal)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -16,13 +16,13 @@ func Request(apiKey string, apiURL string) ([]byte, error) {
|
|||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
data, err := ParseBody(resp)
|
data, err := ParseBody(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, err
|
return data, err
|
||||||
|
@ -5,20 +5,21 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
Name string
|
wtf.BaseWidget
|
||||||
RefreshedAt time.Time
|
View *tview.TextView
|
||||||
RefreshInterval int
|
|
||||||
View *tview.TextView
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
Name: "BambooHR",
|
BaseWidget: wtf.BaseWidget{
|
||||||
RefreshedAt: time.Now(),
|
Name: "BambooHR",
|
||||||
RefreshInterval: 3600,
|
RefreshedAt: time.Now(),
|
||||||
|
RefreshInterval: 3600,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
|
@ -6,21 +6,22 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
"google.golang.org/api/calendar/v3"
|
"google.golang.org/api/calendar/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
Name string
|
wtf.BaseWidget
|
||||||
RefreshedAt time.Time
|
View *tview.TextView
|
||||||
RefreshInterval int
|
|
||||||
View *tview.TextView
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
Name: "Calendar",
|
BaseWidget: wtf.BaseWidget{
|
||||||
RefreshedAt: time.Now(),
|
Name: "Calendar",
|
||||||
RefreshInterval: 60,
|
RefreshedAt: time.Now(),
|
||||||
|
RefreshInterval: 60,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
|
@ -7,18 +7,21 @@ import (
|
|||||||
|
|
||||||
owm "github.com/briandowns/openweathermap"
|
owm "github.com/briandowns/openweathermap"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
RefreshedAt time.Time
|
wtf.BaseWidget
|
||||||
RefreshInterval int
|
View *tview.TextView
|
||||||
View *tview.TextView
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
RefreshedAt: time.Now(),
|
BaseWidget: wtf.BaseWidget{
|
||||||
RefreshInterval: 600,
|
Name: "Weather",
|
||||||
|
RefreshedAt: time.Now(),
|
||||||
|
RefreshInterval: 600,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
@ -110,6 +113,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
|||||||
icon = "🌥"
|
icon = "🌥"
|
||||||
case "partly cloudy":
|
case "partly cloudy":
|
||||||
icon = "🌤"
|
icon = "🌤"
|
||||||
|
case "scattered clouds":
|
||||||
|
icon = "☁️"
|
||||||
case "snow":
|
case "snow":
|
||||||
icon = "❄️"
|
icon = "❄️"
|
||||||
case "sunny":
|
case "sunny":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user