#!/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]
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
# &