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
|
||||
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)
|
||||
|
||||
return items
|
||||
@ -49,6 +53,9 @@ func (client *Client) away(startDate, endDate string) (cal Calendar, err error)
|
||||
)
|
||||
|
||||
data, err := Request(client.apiKey, apiURL)
|
||||
if err != nil {
|
||||
return cal, err
|
||||
}
|
||||
err = xml.Unmarshal(data, &cal)
|
||||
|
||||
return
|
||||
|
@ -16,13 +16,13 @@ func Request(apiKey string, apiURL string) ([]byte, error) {
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := ParseBody(resp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, err
|
||||
|
@ -5,20 +5,21 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
type Widget struct {
|
||||
Name string
|
||||
RefreshedAt time.Time
|
||||
RefreshInterval int
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "BambooHR",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 3600,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -6,21 +6,22 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
"google.golang.org/api/calendar/v3"
|
||||
)
|
||||
|
||||
type Widget struct {
|
||||
Name string
|
||||
RefreshedAt time.Time
|
||||
RefreshInterval int
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Calendar",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 60,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
|
@ -7,18 +7,21 @@ import (
|
||||
|
||||
owm "github.com/briandowns/openweathermap"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
type Widget struct {
|
||||
RefreshedAt time.Time
|
||||
RefreshInterval int
|
||||
wtf.BaseWidget
|
||||
View *tview.TextView
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Weather",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 600,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
@ -110,6 +113,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
||||
icon = "🌥"
|
||||
case "partly cloudy":
|
||||
icon = "🌤"
|
||||
case "scattered clouds":
|
||||
icon = "☁️"
|
||||
case "snow":
|
||||
icon = "❄️"
|
||||
case "sunny":
|
||||
|
Loading…
x
Reference in New Issue
Block a user