Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Sunrise and Sunset times for configurable sunrise_sunset (bool) #40

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
reading_time: false
sunrise_sunset: false
openai_api_key:
openai_base_url:
openai_model:
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ opml_file_path:
markdown_file_prefix:
markdown_file_suffix:
reading_time: false
sunrise_sunset: false
openai_api_key:
openai_base_url:
openai_model:
Expand Down Expand Up @@ -175,6 +176,7 @@ func bootstrapConfig() {
instapaper = viper.GetBool("instapaper")
reading_time = viper.GetBool("reading_time")
show_images = viper.GetBool("show_images")
sunrise_sunset = viper.GetBool("sunrise_sunset")

// Overwrite terminal_mode from config file only if its not set through -t flag
if !terminalMode {
Expand Down
1 change: 1 addition & 0 deletions feeds_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var openaiBaseURL string
var openaiModel string
var reading_time bool
var show_images bool
var sunrise_sunset bool
var myFeeds []RSS
var db *sql.DB

Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/mmcdole/gofeed v1.1.3
github.com/nathan-osman/go-sunrise v1.1.0
github.com/sashabaranov/go-openai v1.14.2
github.com/spf13/viper v1.16.0
modernc.org/sqlite v1.20.0
Expand All @@ -16,7 +17,7 @@ require (
)

require (
github.com/PuerkitoBio/goquery v1.5.1 // indirect
github.com/PuerkitoBio/goquery v1.5.1
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-shiori/go-readability v0.0.0-20220215145315-dd6828d2f09b
Expand All @@ -31,7 +32,6 @@ require (
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/savioxavier/termlink v1.2.1
Expand All @@ -46,9 +46,7 @@ require (
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
Expand Down
45 changes: 3 additions & 42 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func main() {
fp := gofeed.NewParser()
writer := getWriter()
displayWeather(writer)
displaySunriseSunset(writer)

for _, feed := range myFeeds {
parsedFeed := parseFeed(fp, feed.url, feed.limit)
Expand Down
14 changes: 13 additions & 1 deletion weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"strings"
"time"

"github.com/nathan-osman/go-sunrise"
)

type UserAgentTransport struct {
Expand All @@ -25,6 +27,16 @@ func displayWeather(w Writer) {
}
}

func displaySunriseSunset(w Writer) {
if sunrise_sunset && lat != 0 && lon != 0 {
rise, set := sunrise.SunriseSunset(
lat, lon,
time.Now().Year(), time.Now().Month(), time.Now().Day(),
)
w.write(fmt.Sprintf("🌅 %s 🌇 %s", rise.Local().Format("15:04"), set.Local().Format("15:04")))
}
}

func getWeather(lat, lon float64) string {
client := &http.Client{
Transport: &UserAgentTransport{http.DefaultTransport},
Expand All @@ -46,7 +58,7 @@ func getWeather(lat, lon float64) string {
var temperature float64 = res.Properties.Timeseries[0].Data.Instant.Details.AirTemperature
var next_12_hours string = res.Properties.Timeseries[0].Data.Next12Hours.Summary.SymbolCode
var weatherEmoji string = determineWeatherEmoji(next_12_hours)
return fmt.Sprintf("# %d°C %s ️\n", int(temperature+0.5), weatherEmoji)
return fmt.Sprintf("# %d°C %s ️", int(temperature+0.5), weatherEmoji)

}

Expand Down
Loading