#!/bin/env tclsh
package require logger
package require json
package require json::write
package require sqlite3
package require inifile
package require sha1
source config.tcl
source ws.tcl
source jetstream.tcl
source httpd.tcl
source feed.tcl
set log [logger::init tclfeed]
${log}::info "tclfeed v0.0.1"
#::json::write indented 0
### DB STUFF ###
sqlite3 db [::ini::value $config database path]
db eval {SELECT count(*) as n FROM sqlite_master WHERE name="posts";} values {
if ![set values(n)] {
${log}::info "Initializing db!"
db eval {CREATE TABLE posts (uri TEXT NOT NULL PRIMARY KEY, ts TEXT NOT NULL);}
}
}
### JETSTREAM ###
jetstream::listen [::ini::value $config atproto jetstream_host] db
### HTTPD ###
httpd::router main {
/xrpc/app.bsky.feed.getFeedSkeleton {::feed::serve_skeleton {tcl posts}}
}
httpd::listen main 3000
vwait nil