This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-03
Channels
- # adventofcode (151)
- # asami (34)
- # babashka (43)
- # beginners (111)
- # cider (2)
- # clj-kondo (6)
- # cljdoc (12)
- # clojure (140)
- # clojure-australia (10)
- # clojure-europe (14)
- # clojure-france (5)
- # clojure-gamedev (5)
- # clojure-nl (4)
- # clojure-uk (10)
- # clojurescript (20)
- # community-development (9)
- # conjure (1)
- # core-async (4)
- # cryogen (3)
- # cursive (2)
- # datomic (17)
- # emacs (9)
- # events (1)
- # fulcro (27)
- # juxt (8)
- # kaocha (2)
- # lambdaisland (14)
- # off-topic (23)
- # pathom (37)
- # pedestal (2)
- # re-frame (8)
- # reagent (8)
- # reclojure (9)
- # reitit (5)
- # reveal (34)
- # shadow-cljs (27)
- # spacemacs (10)
- # tools-deps (123)
- # vim (28)
- # xtdb (17)
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
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
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?
(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
@U1QQJJK89 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:
babashka/babashka.pods {:git/url ""
;;
: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:
;;; 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"]]]
(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
@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.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).
Yeah, that's great feature!
I'm brainstorming here: https://github.com/borkdude/babashka/issues/473 Feel free to come with ideas.
Nice, thx. 👍
This is the news of the past month: https://github.com/borkdude/babashka/blob/master/doc/news.md#2020-11.
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.
@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