utilities/snippets_cli_go#6: Fetch item by ID and print



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Milestone: v0.1
Created: 27-Sep-24 10:28



Description

#5 implemented the association of an ID to an entry.

So, the next thing that we need to do is to implement support for fetching an item by its ID.

Because IDs are associated whilst iterating during a search, it probably makes most sense to adjust searchFeed so that it can also match on ID.



Toggle State Changes

Activity


assigned to @btasker

verified

mentioned in commit acd7154b282edcae99079122b0c4f3c306e07b0e

Commit: acd7154b282edcae99079122b0c4f3c306e07b0e 
Author: B Tasker                            
                            
Date: 2024-09-27T11:40:02.000+01:00 

Message

feat: introduce ID matching mode (utilities/snippets_cli_go#6)

This doesn't currently do much more than note that the ID matched

+35 -20 (55 lines changed)

The commit above introduces the matching logic.

What we need now is a function which can print the item. I think it makes sense to do it under this ticket so I'll update the title

changed title from Fetch item by ID to Fetch item by ID{+ and print+}

This is where we're going to diverge, quite significantly, from the original script.

The old script fetched JSON which had an attribute for each of the sections. We're going to be fetching HTML and parsing that out.

Obviously, this is also going to mean that we need to define the structure that the site should use once migrated.

The old script's output looks like this

$ sbt_cli 175
175: Calculating the difference between subsequent values in SQL (SQL)

-------------
Details
-------------

Language: SQL

-------------
Description
-------------

It's sometimes desirable to caculate the difference between subsequent points.
This might be necessary, for example, if a record's value is drawn from a cumulative total (such as packet counter on a switch) - we're not really interested in the total value so much as the change over time.
The LAG function can be used to look at the previous value, whilst LEAD can be used to look at the next
If the source is something like a packet counter, it might also be desirable to generate a non-negative difference so that a counter reset doesn't lead to large negative figures being reported.

Similar To
-------------

InfluxQL difference
    Flux difference()


-------------
Snippet
-------------

-- Compare to the previous value
SELECT
   time
   _value - LAG (_value) OVER (order by time) AS _value,
FROM foo


-- Compare to the next value
SELECT
   time
   _value - LEAD (_value) OVER (order by time) AS _value,
FROM foo


-- Non-negative difference
SELECT
   time
   CASE
     WHEN _value - LAG (_value) OVER (order by time) < 0 THEN NULL,
     ELSE _value - LAG (_value) OVER (order by time)
   END as _value
FROM foo


HTML Link
----------
https://snippets.bentasker.co.uk/page-2406152213-Calculating-the-difference-between-subsequent-values-SQL.html

On some snippets there's also an example section.

verified

mentioned in commit 694e17d54fd6fa031bbffbddb64388a4df647b62

Commit: 694e17d54fd6fa031bbffbddb64388a4df647b62 
Author: B Tasker                            
                            
Date: 2024-09-27T12:40:23.000+01:00 

Message

feat: fetch page and start extracting info (utilities/snippets_cli_go#6)

+83 -0 (83 lines changed)

This, not unexpectedly, is quite complicated and will rely entirely on the structure we end up using for snippets.

With the current setup, each section will need to be wrapped in a div:

<div id="snippet">
<pre><code>
foo
</code></pre>
</div>

etc.

Although it's workable, that doesn't lend itself particularly well to the markdown template that I was hoping to use.

One option might be to swap from the html.Parser to html.Tokeniser so that I can look for an attribute with an id (the section heading) and then scoop up everything between it and the next known heading.

I think what we probably need to do next is stand up a local Nikola site so there's something to play around with.

Note: there's a big TODO here - the code currently looks for h4's because I was testing it against a blog post and looking for a heading (because those have IDs).

Actually, thinking about it, do we actually want to make it reliant on that level of granularity?

It might be better to look at how things render if we were to grab a single div (which could be put into the template) and text-ise everything under it. That way minor changes to layout don't lead to us having to update/change this tool.

verified

mentioned in commit 4cc5bed47123aea62361a8520e8fa91bfee0ad8a

Commit: 4cc5bed47123aea62361a8520e8fa91bfee0ad8a 
Author: B Tasker                            
                            
Date: 2024-09-27T13:51:32.000+01:00 

Message

feat: output upstream page as markdown (utilities/snippets_cli_go#6)

I think, though, that we should remove links etc

+93 -30 (123 lines changed)
verified

mentioned in commit a02d007b4287ba310818564d7622fedc25cd2e0f

Commit: a02d007b4287ba310818564d7622fedc25cd2e0f 
Author: B Tasker                            
                            
Date: 2024-09-27T14:06:38.000+01:00 

Message

feat: adjust markdown output for readability (utilities/snippets_cli_go#6)

This prevents inclusion of markdown markup for images and links

The aim here is to generate something that can be read by a human in the console so we want something a little closer to plain text

TODO: tidy up

+29 -3 (32 lines changed)

Re-opening: I forgot to add a print of the full link at the end

verified

mentioned in commit ea2de286cf9c6e54d36abc1f26b2f4a0104cf474

Commit: ea2de286cf9c6e54d36abc1f26b2f4a0104cf474 
Author: B Tasker                            
                            
Date: 2024-09-27T14:27:50.000+01:00 

Message

feat: include page link at bottom of output (utilities/snippets_cli_go#6)

+5 -2 (7 lines changed)

mentioned in issue #8