~aleteoryx/tclfeed-bsky

ref: e7e6818c81278aafe4035e9dac60958e6e72bbc1 tclfeed-bsky/bin/jetstream-stats.tcl -rwxr-xr-x 1.0 KiB
e7e6818cAleteoryx maybe workaround db locking? 25 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
#!/bin/env tclsh
package require logger
package require json

set times [clock microseconds]
set bufsize 10000
proc on_ws {sock mode data} {
  global times bufsize

  set data [json::json2dict $data]

  if {$mode == "close"} {
    ::ws::c::connect jetstream2.us-east.bsky.network 443 /subscribe?wantedCollections=app.bsky.feed.post on_ws
  }

  lappend times [dict get $data time_us]
  set times [lrange $times end-[expr {$bufsize - 1}] end]

  set start [lindex $times 0]
  set end [lindex $times end]

  set micros_per_N [expr {$end - $start}]
  set secs_per_event [expr {$micros_per_N / [llength $times] / 1000000.0}]
  set rate [expr {floor(1.0 / $secs_per_event)}]

  if {[llength $times] < $bufsize} {
    puts -nonewline "\33\[2K\rThe jetstream is producing $rate posts/sec ([llength $times] post sample)"
  } else {
    puts -nonewline "\33\[2K\rThe jetstream is producing $rate posts/sec"
  }
  flush stdout
}

source ws.tcl
::ws::c::connect jetstream2.us-east.bsky.network 443 /subscribe?wantedCollections=app.bsky.feed.post on_ws

vwait nil