4/5/2024 0 Comments Terminal quotesLet's start by just looking for the fields we need, which in this case are "content" and "author". Now that we have the quote data, we need to expand our jq command to parse the necessary JSON fields from the response and format it properly. We'll also add the -s silent flag to avoid seeing the network request bits in the request. Let's change that by piping the result into jq. That's a little difficult to reason about when it's unformatted. The /random route returns a different quote with each request, but the response should look something like this. The route, in particular, is the GET /random route, which you can test with this command. For what I was looking for it was perfect. For being completely free I must say that the API is pretty robust in that it provides a lot of functionality around getting random quotes, quotes by tag, quotes by author, etc. For this, I found a free and open-source option called Quotable, which can be found on GitHub here. To start we need to find an API, preferably one that returns JSON as the response, to provide the quote. We'll be using curl to make the API request and jq to parse the response. ![]() To follow along with this post you'll want to make sure you have installed curl and jq. There are probably several ways to go about this or even an existing library out there to do this for me, but like many things I wanted to take a shot at it myself. ![]() I could head out to any of the popular "quote of the day" sites, but for my use case, I needed (maybe wanted) it in my terminal. I recently was looking for a convenient way to get a random quote printed in my terminal. Let's dive in!Īaron Bos | Monday, SeptemGenerating the Quote While this may seem silly, I think some of this post will be relevant and applicable to other CLI based needs. Home Posts About Generating Random Quotes via CLI Ever needed a bit of inspiration to get your day started? In this post we'll be looking at how we can generate a random quote and easily format and print it in our terminal.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |