From a4484f61e7bb018f3ca52c59271f908e47402858 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 9 Sep 2024 10:21:40 -0700 Subject: [PATCH] adding scm scripts + changes --- .config/doom/init.el | 2 +- .config/doom/packages.el | 1 + .config/waybar/scripts/music.scm | 36 +++++++++++++ .config/waybar/scripts/weather.scm | 83 ++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100755 .config/waybar/scripts/music.scm create mode 100755 .config/waybar/scripts/weather.scm diff --git a/.config/doom/init.el b/.config/doom/init.el index 9f2954d..d96e358 100644 --- a/.config/doom/init.el +++ b/.config/doom/init.el @@ -155,7 +155,7 @@ ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"} ;;rust ; Fe2O3.unwrap().unwrap().unwrap().unwrap() ;;scala ; java, but good - ;;(scheme +guile) ; a fully conniving family of lisps + (scheme +guile) ; a fully conniving family of lisps sh ; she sells {ba,z,fi}sh shells on the C xor ;;sml ;;solidity ; do you need a blockchain? No. diff --git a/.config/doom/packages.el b/.config/doom/packages.el index 0cf8a78..c3a1f03 100644 --- a/.config/doom/packages.el +++ b/.config/doom/packages.el @@ -7,6 +7,7 @@ (package! pomm) (package! mixed-pitch) (package! guess-language) +(package! sicp) ;; Remove (package! dirvish :disable t) diff --git a/.config/waybar/scripts/music.scm b/.config/waybar/scripts/music.scm new file mode 100755 index 0000000..4819886 --- /dev/null +++ b/.config/waybar/scripts/music.scm @@ -0,0 +1,36 @@ +#!/usr/bin/env guile3.0 +!# + +(use-modules (ice-9 popen) + (ice-9 rdelim)) + +;; Function to get playerctl metadata +(define (get-playerctl-metadata field) + (let* ((command (string-append "playerctl --player=strawberry metadata " field)) + (port (open-input-pipe command)) + (output (read-line port))) + (close-pipe port) + output)) + +;; Function to abbreviate a string if it's longer than max-length +(define (abbreviate text max-length) + (if (> (string-length text) max-length) + (string-append (substring text 0 (- max-length 3)) "...") + text)) + +(define music-note "🎵") + +;; Main logic to display artist and title +(let* ((artist (get-playerctl-metadata "artist")) + (title (get-playerctl-metadata "title")) + (display-text + (if (and (string? artist) (string? title)) + (abbreviate (string-append artist " - " title) 30) + #f))) ;; Set to #f if artist or title is not available + (if display-text + (begin + (display music-note) ;; Display the music note icon + (display " ") + (display display-text) + (newline)) + (display ""))) diff --git a/.config/waybar/scripts/weather.scm b/.config/waybar/scripts/weather.scm new file mode 100755 index 0000000..56d8a70 --- /dev/null +++ b/.config/waybar/scripts/weather.scm @@ -0,0 +1,83 @@ +#!/usr/bin/env guile3.0 +!# + +(use-modules (web client) + (json) + (rnrs bytevectors) + (ice-9 receive)) + +(define api-key "99631af2d6db903d1f689c7d2cb13764") +(define city-id "5809844") +(define units "metric") + +;; Construct the openweathermap URL with API token, city ID, and unit of measurement +(define weather-url + (format #f "http://api.openweathermap.org/data/2.5/weather?id=~a&units=~a&appid=~a" + city-id units api-key)) + +;; Define weather icons as an association list +(define weather-icons + '(("clear sky" . "☀️") + ("few clouds" . "🌤️") + ("scattered clouds" . "🌥️") + ("broken clouds" . "☁️") + ("overcast clouds" . "☁️") + ("shower rain" . "🌦️") + ("light rain" . "🌧️") + ("rain" . "🌧️") + ("moderate rain" . "🌧️") + ("thunderstorm" . "⛈️") + ("snow" . "❄️") + ("mist" . "🌫️") + ("haze" . "🌫️") + ("smoke" . "🌫️") + ("fog" . "🌫️"))) + +;; Convert Celsius to Fahrenheit +(define (celsius-to-fahrenheit celsius) + (+ (* celsius (/ 9 5)) 32)) + +;; Get weather icon based on description +(define (get-weather-icon description) + (or (assoc-ref weather-icons description) "❓")) + +;; Parse and extract weather data from JSON +(define (extract-weather-data json-data) + (let* ((main (assoc "main" json-data)) + (temp-c (and main + (cdr (assoc "temp" (cdr main))))) + + ;; Round and convert to exact integer + (temp-c-value (and temp-c + (inexact->exact + (round temp-c)))) + (weather-description + (cdr (assoc "description" + (vector-ref (cdr (assoc "weather" json-data)) 0))))) + + ;; Return temperature (C, F), description, and icon + (values temp-c-value + (and temp-c-value + (inexact->exact + (round (celsius-to-fahrenheit temp-c-value)))) + weather-description + (get-weather-icon weather-description)))) + +;; Fetch and display weather data +(define (get-weather) + ;; Request and parse the data + (receive (response-status response-body) + (http-request weather-url) + (let ((json-data (json-string->scm + (utf8->string response-body)))) + (call-with-values + (lambda () (extract-weather-data json-data)) + (lambda (temp-c temp-f description icon) + + ;; Display the weather information + (if temp-c + (format #t "~a ~d°C / ~d°F~%" + icon temp-c temp-f) + (display "Error: Temperature data not available.\n"))))))) + +(get-weather)