blog.notmyidea.org/content/code/2024-06-03-readeck-api-extract-as-md.md
2024-06-13 19:18:24 +02:00

2.9 KiB

title tags status
Generating my weeknotes quotes with jq and readeck readeck, jq, markdown draft

I've installed readeck to track the articles I read, and I'm currently trying to make it a database for the quotes I do. Because there is a nice Firefox add-on I hope it will be convenient to use.

Readeck proposes an API to retrieve the data it stores, and I wanted to leverage it to build my weeknotes citations.

The API provided is very easy to query, and returns JSON:


curl -X GET "https://readeck.notmyidea.org/api/bookmarks/annotations" -H "accept: application/json" -H "authorization: Bearer <redacted>" | jq

Returns:

[
  {
    "id": "RpgpsT2ZijHsbiwX9fL3He",
    "href": "http://readeck.notmyidea.org/api/bookmarks/fJ6SRgbUJXdNt3QGrvb2aP/annotations/RpgpsT2ZijHsbiwX9fL3He",
    "text": "Fourth, power matters. AI is a technology that fundamentally magnifies power of the humans who use it, but not equally across users or applications. Can we build systems that reduce power imbalances rather than increase them? Think of the privacy versus surveillance debate in the context of AI.",
    "created": "2024-06-02T22:16:46.80538957+02:00",
    "bookmark_id": "fJ6SRgbUJXdNt3QGrvb2aP",
    "bookmark_href": "http://readeck.notmyidea.org/api/bookmarks/fJ6SRgbUJXdNt3QGrvb2aP",
    "bookmark_url": "https://www.schneier.com/blog/archives/2024/05/how-ai-will-change-democracy.html",
    "bookmark_title": "How AI Will Change Democracy",
    "bookmark_site_name": "Schneier on Security"
  },
  ...
]

From there, turning this to Markdown was this jq filter:

.[] | "> \(.text) \n> \n> — [\(.bookmark_title)](\(.bookmark_url))\n"

Using jq -r to output as raw output, I get the quote I'm looking for:


> Fourth, power matters. AI is a technology that fundamentally magnifies power of the humans who use it, but not equally across users or applications. Can we build systems that reduce power imbalances rather than increase them? Think of the privacy versus surveillance debate in the context of AI.
> 
> — [How AI Will Change Democracy](https://www.schneier.com/blog/archives/2024/05/how-ai-will-change-democracy.html)  

Because I write these notes every week, I'm only interested in the content of the last week.

Here is how to get "last-week-date" on macOS:

date -v-7d +"%Y-%m-%d"

And I can filter with:

jq --arg date $(date -v-7d +"%Y-%m-%d") '.[] | select(.created > $date)'

Putting it all together, I have the following line:


curl -X GET "https://readeck.notmyidea.org/api/bookmarks/annotations" -H "accept: application/json" -H "authorization: Bearer <redacted>" \
| jq -r --arg date $(date -v-7d +"%Y-%m-%d") \
'.[] | select(.created > $date) | "> \\(.text) \\n> \\n> — [\\(.bookmark_title)](\\(.bookmark_url))\\n"'```

I feel like a hairy terminal monster, with smiling eyes.