mirror of
https://github.com/edufeed-org/amb-publisher.git
synced 2025-12-10 00:34:35 +00:00
initial commit
This commit is contained in:
commit
3088f54904
4 changed files with 85 additions and 0 deletions
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
.calva/output-window/
|
||||||
|
.calva/repl.calva-repl
|
||||||
|
.classpath
|
||||||
|
.clj-kondo/.cache
|
||||||
|
.cpcache
|
||||||
|
.eastwood
|
||||||
|
.factorypath
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
|
.java-version
|
||||||
|
.lein-*
|
||||||
|
.lsp/.cache
|
||||||
|
.lsp/sqlite.db
|
||||||
|
.nrepl-history
|
||||||
|
.nrepl-port
|
||||||
|
.portal/vs-code.edn
|
||||||
|
.project
|
||||||
|
.rebel_readline_history
|
||||||
|
.settings
|
||||||
|
.socket-repl-port
|
||||||
|
.sw*
|
||||||
|
.vscode
|
||||||
|
*.class
|
||||||
|
*.jar
|
||||||
|
*.swp
|
||||||
|
*~
|
||||||
|
/checkouts
|
||||||
|
/classes
|
||||||
|
/target
|
||||||
|
|
||||||
|
*.jsonl
|
||||||
10
README.md
Normal file
10
README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# AMB Publisher
|
||||||
|
|
||||||
|
Publishes AMB data from a json-file to some relay.
|
||||||
|
|
||||||
|
`clj -X publisher.core/process-json-lines-file :path resources/oersi_data.jsonl`
|
||||||
|
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
- [ ] make relay configurable
|
||||||
5
deps.edn
Normal file
5
deps.edn
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{:deps {clj-http/clj-http {:mvn/version "3.13.0"}
|
||||||
|
cheshire/cheshire {:mvn/version "5.13.0"}
|
||||||
|
hato/hato {:mvn/version "1.0.0"}
|
||||||
|
nostr/nostr {:local/root "/home/steffen/coding/nostr-clj"}}}
|
||||||
|
|
||||||
39
src/publisher/core.clj
Normal file
39
src/publisher/core.clj
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
(ns publisher.core
|
||||||
|
(:require [nostr.edufeed :as edufeed]
|
||||||
|
[nostr.event-composer :as event-composer]
|
||||||
|
[clojure.java.io :as io]
|
||||||
|
[hato.websocket :as ws]
|
||||||
|
[cheshire.core :as json]))
|
||||||
|
|
||||||
|
(defn create-websocket []
|
||||||
|
;; Create the WebSocket connection and return it
|
||||||
|
(let [ws @(ws/websocket "ws://localhost:7778"
|
||||||
|
{:on-message (fn [ws msg last?]
|
||||||
|
(when last?
|
||||||
|
(println msg)))
|
||||||
|
:on-close (fn [ws status reason]
|
||||||
|
(println "WebSocket closed with reason:" reason))})]
|
||||||
|
ws))
|
||||||
|
|
||||||
|
(defn send-to-relay [ws raw-event]
|
||||||
|
(let [signed-event (event-composer/body->event raw-event "9109ffc9fcddb1086e153ed23ff91c4f69f726178bf959f09b1f29c7569e24a1")
|
||||||
|
_ (println (json/generate-string signed-event))]
|
||||||
|
(ws/send! ws (json/generate-string signed-event))))
|
||||||
|
|
||||||
|
(defn save-to-jsonl [data file-path]
|
||||||
|
(with-open [writer (io/writer file-path :append true)]
|
||||||
|
(.write writer (str (json/generate-string data) "\n"))))
|
||||||
|
|
||||||
|
(defn process-json-line [raw-event]
|
||||||
|
(save-to-jsonl raw-event "events.jsonl"))
|
||||||
|
|
||||||
|
(defn process-json-lines-file [file-path]
|
||||||
|
(let [ws (create-websocket)]
|
||||||
|
(with-open [reader (io/reader "resources/oersi_data.jsonl")]
|
||||||
|
(doseq [line (line-seq reader)]
|
||||||
|
(let [json-data (json/parse-string line true)
|
||||||
|
raw-event (edufeed/transform-amb-to-30142-event (:_source json-data))
|
||||||
|
]
|
||||||
|
(process-json-line raw-event)
|
||||||
|
(send-to-relay ws raw-event))))))
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue