From 0c22852e3958797ce482f96ad19f7b5df34a32a2 Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Fri, 8 Nov 2024 17:45:05 -0600 Subject: [PATCH 1/2] added support for weather location --- config/config.toml | 1 + scripts/test_config.toml | 1 + src/catnaplib/platform/fetch.nim | 2 +- src/catnaplib/platform/probe.nim | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/config.toml b/config/config.toml index 897b2f8..6bb0c79 100644 --- a/config/config.toml +++ b/config/config.toml @@ -34,6 +34,7 @@ colors = {icon = " ", name = "colors", color = "!DT!", symbol = ""} borderstyle = "line" layout = "Inline" # [Inline, ArtOnTop, StatsOnTop] stats_margin_top = 0 +location = "" # Used for fetching weather; leave empty to use the location of your IP; check https://wttr.in/:help for supported location types [misc.figletLogos] # Requires Figlet. enable = false diff --git a/scripts/test_config.toml b/scripts/test_config.toml index 03eab5d..08d189c 100644 --- a/scripts/test_config.toml +++ b/scripts/test_config.toml @@ -26,6 +26,7 @@ colors = {icon = "> ", name = "colors", color = "!DT!", symbol = "#"} borderstyle = "doubleline" layout = "Inline" stats_margin_top = 0 +location = "San Francisco" [misc.figletLogos] enable = false diff --git a/src/catnaplib/platform/fetch.nim b/src/catnaplib/platform/fetch.nim index f57b9fb..fe4a289 100644 --- a/src/catnaplib/platform/fetch.nim +++ b/src/catnaplib/platform/fetch.nim @@ -23,7 +23,7 @@ proc fetchSystemInfo*(config: Config, distroId: string = "nil"): FetchInfo = result.list["cpu"] = proc(): string = return probe.getCpu() result.list["gpu"] = proc(): string = return probe.getGpu() result.list["packages"] = proc(): string = return probe.getPackages() - result.list["weather"] = proc(): string = return probe.getWeather() + result.list["weather"] = proc(): string = return probe.getWeather(config.misc["location"].getStr()) if defined(linux): # Add a disk stat for all mounts let mounts: seq[string] = probe.getMounts() diff --git a/src/catnaplib/platform/probe.nim b/src/catnaplib/platform/probe.nim index 1576bb5..7330c70 100644 --- a/src/catnaplib/platform/probe.nim +++ b/src/catnaplib/platform/probe.nim @@ -351,7 +351,7 @@ proc getGpu*(): string = writeCache(cacheFile, result, initDuration(days=1)) -proc getWeather*(): string = +proc getWeather*(location: string): string = # Returns current weather let cacheFile = "weather".toCachePath @@ -360,7 +360,7 @@ proc getWeather*(): string = return let tmpFile = "weather.txt".toTmpPath - if execCmd("curl -s wttr.in/?format=3 > " & tmpFile) != 0: + if execCmd("curl -s wttr.in/" & location & "?format=3 > " & tmpFile) != 0: logError("Failed to fetch weather!") result = readFile(tmpFile).strip() From 0130ad7a86078a51a4451f1a8cadcdde39f3830d Mon Sep 17 00:00:00 2001 From: Rui Jiang Date: Fri, 8 Nov 2024 17:47:15 -0600 Subject: [PATCH 2/2] updated sample config --- config/config.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.toml b/config/config.toml index 6bb0c79..239f984 100644 --- a/config/config.toml +++ b/config/config.toml @@ -18,12 +18,12 @@ terminal = {icon = " ", name = "term", color = "(RD)"} shell = {icon = " ", name = "shell", color = "(MA)"} # packages = {icon = " ", name = "packages", color = "(RD)"} # WARNING: Resource Intensive # weather = {icon = " ", name = "weather", color = "(BE)"} # Requires curl and an emoji font. | WARNING: Resource Intensive -# The following stats do not work on MacOS and the BSDs. # gpu = {icon = "󱔐 ", name = "gpu", color = "(MA)"} # WARNING: Resource Intensive # cpu = {icon = " ", name = "cpu", color = "(RD)"} +# battery = {icon = " ", name = "battery", color = "(GN)"} +# The following stats do not work on MacOS and the BSDs. # disk_0 = {icon = " ", name = "disk", color = "(GN)"} # memory = {icon = " ", name = "memory", color = "(YW)"} -# battery = {icon = " ", name = "battery", color = "(GN)"} sep_color = "SEPARATOR" colors = {icon = " ", name = "colors", color = "!DT!", symbol = ""}