babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2020-12-03T06:44:08.044300Z

Thanks @tvaughan I'll check your links. πŸ‘

jumar 2020-12-03T06:52:22.044600Z

Thanks, updated from v0.2.2 to v0.2.4 and it works now

jumar 2020-12-03T08:21:40.046100Z

In https://book.babashka.org/#_scripts there's this: > When writing scripts instead of one-liners on the command line, it is not recommended to useΒ `*input*` May ask about more details why this isn't recommended? E.g. Nate uses user/*input* in his scripts: https://github.com/justone/bb-scripts/blob/master/src/comb.clj#L31

borkdude 2020-12-03T08:23:11.046800Z

@jumar I prefer not to since it's not obvious from the script what the corresponding i/o flags on the command line should be

jumar 2020-12-03T08:24:44.048100Z

Ah, so the shape of *input* will vary depending on -i vs -I but *in* stays the same, right? It would be great to add a little note to the babashka book's section referenced above

borkdude 2020-12-03T08:25:25.048500Z

ok, will do

jumar 2020-12-03T08:25:41.048700Z

Great, many thanks!

πŸ‘ 1
jumar 2020-12-03T09:41:02.049800Z

What's the recommended way to parse html in a babashka script? I looked at https://github.com/borkdude/babashka/blob/master/doc/projects.md#pods and found https://github.com/jaydeesimon/pod-jaydeesimon-jsoup but I'm not sure what are these "pods" about and how they differ from "libraries".

borkdude 2020-12-03T09:43:05.050700Z

@jumar pods are CLIs that you can use as libraries from within babashka. So instead of shelling out manually you can just require a namespace and call functions.

borkdude 2020-12-03T09:44:10.051100Z

@jumar the bootleg pod is the most common one to use for HTML parsing and production: https://github.com/retrogradeorbit/bootleg#babashka-pod-usage

jumar 2020-12-03T09:47:06.052100Z

Hmm, but I'd like to just use a library without having to install any additional tool. Is there another option?

borkdude 2020-12-03T09:48:08.052900Z

Not currently. But babashka will try to make working with pods easier in the future, so the pod will be automatically downloaded if you put it in the babashka.edn (which does not exist yet).

πŸ‘ 1
πŸ’― 1
jumar 2020-12-03T09:48:20.053100Z

Ok, thanks for you help!

2020-12-03T10:10:32.053300Z

Yeah, that's great feature!

borkdude 2020-12-03T10:15:17.053500Z

I'm brainstorming here: https://github.com/borkdude/babashka/issues/473 Feel free to come with ideas.

2020-12-03T10:42:39.053900Z

Nice, thx. πŸ‘

jumar 2020-12-03T11:06:14.054100Z

I've been trying to use bootleg to parse an HTML (string) for a while but was unable to do so. How can I do that? I basically want to parse the string into a navigable structure - hiccup or similar. Do you know if bootleg exposes a function that I can use?

borkdude 2020-12-03T11:06:39.054300Z

ok, let me try it

borkdude 2020-12-03T11:07:46.054500Z

(ns bootleg-script
  (:require [babashka.pods :as pods]))

(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.utils :as utils])

(-> "<a>Hello</a>"
    (utils/convert-to :hiccup))

πŸŽ‰ 1
borkdude 2020-12-03T11:08:20.054700Z

The utils/convert-to function is a versatile function which converts strings (HTML) to something else and EDN (hiccup) to HTML

borkdude 2020-12-03T11:09:13.054900Z

@retrogradeorbit might also be able to chime in here if he wants. I know he's been busy with other stuff lately. (Hope you're doing alright!)

jumar 2020-12-03T11:10:31.055200Z

Hmm, I now tried in in the bb repl and it works as you showed. My problem is that I tried to use this in a clojure repl (deps.edn - something like Nate uses): deps.edn:

{:aliases {:clj {:extra-deps {;; Additional libs for clojure to match babashka includes
                              org.clojure/tools.cli {:mvn/version "1.0.194"}
                              org.clojure/data.csv {:mvn/version "1.0.0"}
                              org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}
                              babashka/babashka.curl {:mvn/version "0.0.1"}
                              ;; used pods to load bootleg for HTML parsing: <https://github.com/retrogradeorbit/bootleg#babashka-pod-usage>
                              babashka/babashka.pods {:git/url "<https://github.com/babashka/pods.git>"
                                                      ;; <https://github.com/babashka/pods/commit/1417f30fc4001cc9490b5f83c68630ea877d92d6>
                                                      :sha "1417f30fc4001cc9490b5f83c68630ea877d92d6"}
                              cheshire/cheshire {:mvn/version "5.10.0"}}
                 :extra-paths ["dev"]}}
 :paths ["src"]
 :deps {
        clj-tagsoup/clj-tagsoup {:mvn/version "0.3.0"}}}
In this script:
(ns html  (:require [babashka.curl :as curl]
            #_[pl.danieljanus.tagsoup :as html]
            [babashka.pods :as pods]
            ))

;;; use pods to load bootleg for html parsing: <https://github.com/retrogradeorbit/bootleg#babashka-pod-usage>
;;; Note that you have to install bht pod on the system first!
(pods/load-pod "bootleg")
(require '[pod.retrogradeorbit.bootleg.utils :as utils])

(utils/html-&gt;hiccup "&lt;html&gt;&lt;body&gt;&lt;p&gt;ahoj&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;")
It just freezes on the last line so I guess this isn't a supported use case?

borkdude 2020-12-03T11:18:04.055500Z

Works fine over here:

$ bb /tmp/bootleg.clj
[:a "Hello"]
[:html [:body [:p "ahoj"]]]

borkdude 2020-12-03T11:18:30.055700Z

ah a Clojure repl

jumar 2020-12-03T11:20:03.055900Z

(Yes, working in cider and starting the repl as usual with cider-jack-in using the deps.edn file)

borkdude 2020-12-03T11:22:31.056100Z

I think this is due to an incompatibility with pods on the JVM and in sci. For now you could try to use the babashka nREPL

borkdude 2020-12-03T11:22:44.056300Z

And please make an issue about this at babashka pods

borkdude 2020-12-03T11:23:41.056500Z

Nm, I will make an issue now

borkdude 2020-12-03T11:24:59.056700Z

https://github.com/babashka/pods/issues/25

jumar 2020-12-03T11:25:41.057100Z

Perfect, thanks!

borkdude 2020-12-03T11:27:24.057300Z

Ah, I found it. Put a (require '[clojure.zip]) before loading the pod

borkdude 2020-12-03T11:29:45.057500Z

@jumar So, this should work on the JVM:

(ns html  (:require [babashka.pods :as pods]))

(require '[clojure.zip])
(def pod (pods/load-pod "bootleg"))
(require '[pod.retrogradeorbit.bootleg.utils :as utils])
(prn (utils/html-&gt;hiccup "&lt;html&gt;&lt;body&gt;&lt;p&gt;ahoj&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;"))

(pods/unload-pod pod)
(shutdown-agents)

borkdude 2020-12-03T11:30:10.057700Z

Note that I added:

(pods/unload-pod pod)
(shutdown-agents)
to make the JVM exit normally.

jumar 2020-12-03T11:34:07.057900Z

Excellent! Thanks again.

isak 2020-12-03T18:36:04.058500Z

What do you guys do to report progress to the user?

isak 2020-12-03T18:38:15.058600Z

This may work: https://github.com/weavejester/progrock

βœ”οΈ 3
borkdude 2020-12-03T19:24:01.059100Z

Nice find!

borkdude 2020-12-03T19:24:31.059300Z

https://github.com/weavejester/progrock works with babashka!

πŸ‘ 1
😍 1
borkdude 2020-12-03T19:24:47.059700Z

🀘 3
πŸš€ 7
isak 2020-12-03T19:26:53.060Z

yea it was very cool to see that it just worked πŸ™‚

borkdude 2020-12-03T19:49:31.061300Z

This is the news of the past month: https://github.com/borkdude/babashka/blob/master/doc/news.md#2020-11.

πŸŽ‰ 5
nate 2020-12-03T19:56:53.061800Z

great summary, thanks for putting it together!

dgb23 2020-12-03T20:38:06.063900Z

nice touch: &lt;summary&gt;&lt;details&gt; is used on the https://github.com/xapix-io/matchete readme. First time I see this is a readme. It’s a simple trick to give the layout a bit more hierarchy.

dgb23 2020-12-03T20:38:58.064400Z

(the lib is mentioned in the babashka news article)

borkdude 2020-12-03T20:44:43.065600Z

@denis.baudinot yeah, certainly. Maybe I'm going to convert the projects.md and news.md page to this format as well: https://book.babashka.org/ So you will have http://babashka.org/news, http://babashka.org/projects with a nice UI