One way would be to call gz topic --view ... from a script.
Another way is to write a node which copies what the gz topic --view command line tool is doing. Here is the code for that tool.