~aleteoryx/tclfeed-bsky

ref: 118a66cedc632097547210d6754258aa3f579e84 tclfeed-bsky/main.tcl -rwxr-xr-x 913 bytes
118a66ceAleteoryx well, until i exist on jetstream, ig this is where this project ends 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
#!/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

# &