Created
October 25, 2024 22:28
-
-
Save refaktor/cde07e01aed6809eb37e582b12c048ea to your computer and use it in GitHub Desktop.
a little more advanced music nad hn utilities ... stil work in progress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; main.rye ... you can start this with rye -console . when in the same directory | |
music: context { | |
list: fn { "retrieves and lists soma.fm streams" } { | |
get https://soma.fm | |
|reader | |
|parse-html { <a> [ .attr? 'href |collect! ] } ; NOTE: collect / collected is a temp idea, don't like it that much but it solves some cases | |
pop-collected! | |
|filter { .is-match* regexp "^\/[a-z]+\.pls$" } | |
|map { .submatch?* regexp "\/([a-z]+)\." } | |
|display | |
} | |
favorite: { "defcon" "spacestation" "lush" } | |
play: fn { pls "plays a specific soma.fm stream" } | |
{ .embed "mpv --no-video https://somafm.com/{}.pls" |cmd } | |
autoplay: fn { "plays a random favorite stream" } | |
{ random favorite |pass { prn "Randomly selected " , .prn } |play } | |
} | |
hn: context { | |
priv: context { | |
https://hacker-news.firebaseio.com/v0/ :hn | |
get-item: fn { id } { .embed hn + "item/{}.json" |get |parse-json } | |
maybe-comments: fn { row } { | |
if row .type? = 'spreadsheetrowtype { | |
row -> "id" |get-item -> "kids" | |
|for { | |
.to-integer .get-item | |
|with { term/bold , -> "by" |print term/reset\bold , -> "text" |print } } | |
} | |
} | |
} | |
last-list: spreadsheet { "title" "id" } { } | |
top: fn { n "lists top 10 stories" } { | |
priv/hn + "topstories.json" |get |parse-json |head n | |
|map { | |
.to-integer .priv/get-item ::x , | |
[ | |
x -> "title" | |
x -> "id" |to-integer | |
] | |
} | |
|to-block |unpack | |
|spreadsheet* { "title" "id" } | |
|pass { .change! 'last-list } | |
|display .priv/maybe-comments | |
} | |
again: does { either is-empty last-list { print "get it first" } { last-list .display .priv/maybe-comments } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment