2024-02-26 16:55:18 +01:00
|
|
|
#!/usr/bin/env hy
|
|
|
|
(import httpx)
|
|
|
|
(import loguru [logger])
|
|
|
|
(import app [config])
|
2024-02-28 06:45:13 +01:00
|
|
|
(import app.httpsig [auth])
|
|
|
|
|
2024-02-26 16:55:18 +01:00
|
|
|
|
|
|
|
(defn/a fetch
|
|
|
|
[url]
|
|
|
|
(.info logger url)
|
|
|
|
(return (.json
|
|
|
|
(with/a [client (.AsyncClient httpx)]
|
2024-02-26 17:27:01 +01:00
|
|
|
(let [headers {"User-Agent" config.USER_AGENT
|
|
|
|
"Accept" config.AP_CONTENT_TYPE}]
|
|
|
|
(await (.get client url :headers headers)))))))
|
2024-02-28 06:45:13 +01:00
|
|
|
|
|
|
|
(defn/a post
|
|
|
|
[url payload]
|
|
|
|
(with/a [client (.AsyncClient httpx)]
|
|
|
|
(let [headers {"User-Agent" config.USER_AGENT
|
|
|
|
"Accept" config.AP_CONTENT_TYPE}]
|
|
|
|
(setv resp
|
|
|
|
(await (.post client url :headers headers :json payload :auth auth)))
|
|
|
|
(.raise_for_status resp)
|
|
|
|
(return resp))))
|