Fork me on GitHub
#babashka
<
2021-01-24
>
bherrmann01:01:28

bah, I need to process some html (specifically to pull data out of a table.) I know there is a jsoup pod... but is there anything lighter weight?

bherrmann02:01:55

Regex for the win... (def rows (drop 1 (clojure.string/split table-contents #"<tr class=\"\w+\">")))

borkdude09:01:51

@bherrmann

#!/usr/bin/env bb

(require '[babashka.pods :as pods])

(pods/load-pod 'retrogradeorbit/bootleg "0.1.9")

(require '[pod.retrogradeorbit.bootleg.utils :as utils])

(-> "<html><p>Hello</p></html>"
    (utils/convert-to :hiccup))
;; => [:html [:p "Hello"]]

👏 6
borkdude09:01:11

This pod will self-install itself

bherrmann15:01:05

Thanks, I now realize I need to do even more parsing... I have to pull data out of a simple form. Life is too short to parse HTML with regex and indexOf and subs() - I will try the pod.

borkdude20:01:20

I am going to include test.check as a preparation for including clojure.spec in babashka. https://github.com/babashka/babashka/pull/717 clojure.spec will be included when it's clear what happens to alpha and version 2, but I've already made a start with this as a feature flag, which is disabled by default.

nice 3
borkdude21:01:19

Released babashka 0.2.8 with additional built-in libraries: - core.match (much requested) - clojure.test.check (prep for including spec once it comes out of alpha) - hiccup (who doesn't use it?) https://github.com/babashka/babashka/blob/master/CHANGELOG.md#v028

👍 12
🔥 3
nate21:01:43

Awesome!

jaide21:01:49

What’s the recommended way to connect to a postgres db via babashka?

borkdude22:01:55

Welcome btw!

jaide22:01:54

Thanks on both accounts 😄

jaide22:01:26

./test.clj
/home1/[redacted]/.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home1/[redacted]/.babashka/pods/repository/org.babashka/postgresql/0.0.1/pod-babashka-postgresql)
Is there a way to get a static binary for this or should I try a different route?

borkdude22:01:02

@jayzawrotny Are you running this in an alpine docker container?

jaide22:01:28

It’s a shared hosting environment as a cgi-script for learning\experimenting.

borkdude22:01:31

currently we don't have a static version of this pod. theoretically it's possible

borkdude22:01:05

you can compile it yourself locally, it's not hard

borkdude22:01:29

the other way of connecting to postgres would be to shell out to psql

borkdude22:01:46

There is even a library around shelling out to psql for bb: https://github.com/DarinDouglass/clj-psql

borkdude22:01:53

But this was before there were pods.

jaide22:01:59

Great! I did see that library mentioned in the docs but was curious about alternatives. The psql bin does exist on this server so shelling out should be doable, but local compile then uploading might be more performant I’m guessing? Any docs on compiling it locally? Should I setup a docker container to match the host environment?

borkdude22:01:02

And there is another way: there is a feature flag in babashka itself which includes the postgres driver. So you could have a static babashka with postgres support and you could then upload this to your shared env.

jaide22:01:29

I did upload the static babashka already

borkdude22:01:07

@jayzawrotny yeah, so you could compile the pod statically, or you could compile babashka statically with pg support enabled

borkdude22:01:27

then you would have it built into bb, you can require next.jdbc directly without the pod

jaide22:01:51

That could work too for sure. This is quite exciting!

jaide22:01:51

Thanks very much!

borkdude22:01:31

Be sure to use GraalVM java11-20.3.0.

👍 3
jaide23:01:31

After a bit of research I’m going to start with compiling the pods. As it stands, I’m unable to use any pods at runtime so tackling this is a must for any definitive guide. Fortunately those links gave me enough info to get that going.