~aleteoryx/tclfeed-bsky

ref: e5aec4d82ae051b61acc801add365b108b6d51d5 tclfeed-bsky/main.tcl -rwxr-xr-x 1.1 KiB
e5aec4d8Aleteoryx multiple algos, file reorg 30 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/env tclsh
package require logger
package require json
package require json::write
package require sqlite3
package require inifile
package require sha1

source src/config.tcl

source src/at.tcl
source src/ws.tcl
source src/jetstream.tcl
source src/httpd.tcl
source src/feed.tcl

source src/algos.tcl

set log [logger::init tclfeed]
${log}::info "tclfeed v0.0.1"

### DB STUFF ###
sqlite3 db [::ini::value $config database path]

foreach algo $::algos::list {
  db eval {SELECT count(*) as n FROM sqlite_master WHERE name=$algo;} values {
    if ![set values(n)] {
      ${log}::info "Creating table \"$algo\"!"
      if [info exists ::algos::${algo}::cols] {
        db eval "CREATE TABLE $algo (uri TEXT NOT NULL PRIMARY KEY, ord TEXT NOT NULL, [set ::algos::${algo}::cols]);"
      } else {
        db eval "CREATE TABLE $algo (uri TEXT NOT NULL PRIMARY KEY, ord TEXT NOT NULL);"
      }
    }
  }
}

### JETSTREAM ###
jetstream::listen [::ini::value $config atproto jetstream_host] $::algos::list

### HTTPD ###
httpd::router main [list \
  /xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton $::algos::list] \
]
httpd::listen main 3000

vwait nil