Thanks @tvaughan I'll check your links. π
Thanks, updated from v0.2.2 to v0.2.4 and it works now
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
@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
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
ok, will do
Great, many thanks!
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".
@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.
@jumar the bootleg pod is the most common one to use for HTML parsing and production: https://github.com/retrogradeorbit/bootleg#babashka-pod-usage
Hmm, but I'd like to just use a library without having to install any additional tool. Is there another option?
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).
Ok, thanks for you help!
Yeah, that's great feature!
I'm brainstorming here: https://github.com/borkdude/babashka/issues/473 Feel free to come with ideas.
Nice, thx. π
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?
ok, let me try it
(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))
The utils/convert-to function is a versatile function which converts strings (HTML) to something else and EDN (hiccup) to HTML
@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!)
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->hiccup "<html><body><p>ahoj</p></body></html>")
It just freezes on the last line so I guess this isn't a supported use case?Works fine over here:
$ bb /tmp/bootleg.clj
[:a "Hello"]
[:html [:body [:p "ahoj"]]]
ah a Clojure repl
(Yes, working in cider and starting the repl as usual with cider-jack-in using the deps.edn file)
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
And please make an issue about this at babashka pods
Nm, I will make an issue now
Perfect, thanks!
Ah, I found it.
Put a (require '[clojure.zip])
before loading the pod
@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->hiccup "<html><body><p>ahoj</p></body></html>"))
(pods/unload-pod pod)
(shutdown-agents)
Note that I added:
(pods/unload-pod pod)
(shutdown-agents)
to make the JVM exit normally.Excellent! Thanks again.
What do you guys do to report progress to the user?
This may work: https://github.com/weavejester/progrock
Nice find!
https://github.com/weavejester/progrock works with babashka!
yea it was very cool to see that it just worked π
This is the news of the past month: https://github.com/borkdude/babashka/blob/master/doc/news.md#2020-11.
great summary, thanks for putting it together!
nice touch: <summary><details>
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.
(the lib is mentioned in the babashka news article)
@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