adding scm scripts + changes

This commit is contained in:
2024-09-09 10:21:40 -07:00
parent 11deb87570
commit a4484f61e7
4 changed files with 121 additions and 1 deletions

View File

@@ -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.

View File

@@ -7,6 +7,7 @@
(package! pomm)
(package! mixed-pitch)
(package! guess-language)
(package! sicp)
;; Remove
(package! dirvish :disable t)

View File

@@ -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 "")))

View File

@@ -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)