Announcing the Hacker News command library

To use the Linux on the Web system, you must first decide whether you want to simply "get down to business" (via the CLI), or whether you want access to all the graphical "bells and whistles" (via the Desktop environment).

Once you are staring at a terminal prompt, you need to import the Hacker News command library into the system as such:

import net.hn

To see which commands are available to you from that libary, you can run:

lib net.hn

To get a basic rundown of the individual commands, do something like this:

help <command_name>

For example, for a rundown of the command to retrieve the current top stories, do:

help hntop

Many of the commands are specifically geared towards the WebSQL API, which is not available in all browsers, so YMMV (as they say). If you do want to play around with those commands, you will need to run this first:

hnmktab --all

If that command fails, you will have to use try another browser to use certain commands.

In any event, you will need to run the following command in order to establish a connection with the service (Firebase) that provides the data.

hnfbup

Now, this will give you a listing of the item ids of the current top 10 stories:

hntop 10
To fetch and locally store the actual data structures (so that the results can be used for offline data mining), you must add the 'get' flag, like so:
hntop 10 --get

All of the commands up to now have been "one and done", that is, they just do a one-time fetch of data and then return. But Firebase also offers the ability to wait for changes to data structures, such as lists of top stories. To see the top ten stories as they are immediately updated on the Hacker News server, do this:

hntop 10 --get --watch

But this accomplishes nothing more than occassionally spitting out bunches of text like this:

[object HNItem(22561328)]
[object HNItem(22560962)]
[object HNItem(22560484)]
[object HNItem(22560075)]
[object HNItem(22559840)]
[object HNItem(22561147)]
[object HNItem(22559384)]
[object HNItem(22557137)]
[object HNItem(22559813)]
[object HNItem(22558422)]

If you actually want to begin to engage with the preceding objects, you will need to use a pipeline. The relevant command in the Hacker News command library is called 'hnpipe', and can be used like this:

hntop 10 --get --watch | hnpipe --html

But the final result of this command still leaves something to be desired. Even though the output is somewhat more intelligible than the object strings above, it is still merely a bunch of text splattered onto the terminal's display.

Now, if you happen to be in the desktop environment, you can import the 'gui' library (hopefully you can figure out how), and then run the following command:

hntop 10 --get --watch | hnpipe --html | render

Well, that is pretty good, but still not perfect, since the story items that are occasionally spit out of the 'hntop' command are merely appended to the bottom of the output window. The following command fixes that problem by spitting out a "clear display" instruction to the renderer, every time that the updated listing is received from the service:

hntop 10 --get --watch --clear | hnpipe --html | render

As a final touch, we can also send a "show timestamp" instruction to the renderer as such:

hntop 10 --get --watch --clear --time | hnpipe --html | render

And finally, for those who like terseness over verbosity, the following command will give the exact same results:

hntop 10 -gwct | hnpipe -h | render