<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>jq on foosel.net</title><link>https://foosel.net/tags/jq/</link><description>Recent content in jq on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Wed, 09 Jul 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/jq/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to set the internal schedule on a Roomba 960 using rest980</title><link>https://foosel.net/til/2025-07-09-how-to-set-the-internal-schedule-on-a-roomba-960-using-rest980/</link><pubDate>Wed, 09 Jul 2025 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2025-07-09-how-to-set-the-internal-schedule-on-a-roomba-960-using-rest980/</guid><description>&lt;p&gt;For some reason my Roomba 960 decided to fall off the cloud, or at least the official app refuses to see it.&lt;/p&gt;
&lt;p&gt;I thankfully already have an instance of &lt;a href="https://github.com/koalazak/rest980"&gt;rest980&lt;/a&gt; running in my homelab anyhow, and it is still happily chatting with
the bot. And tbh, I might just block cloud access again as having everything local is better anyhow.&lt;/p&gt;
&lt;p&gt;In any case, I wanted to disable the schedule currently set on it internally to switch to scheduling stuff from my home automation,
but without the app working I wasn&amp;rsquo;t sure on how. So I went hunting through rest980&amp;rsquo;s source - as the README didn&amp;rsquo;t tell me what
I was looking for - and found that I could program the weekly schedule with some easy &lt;code&gt;curl&lt;/code&gt; magic via the &lt;code&gt;/api/local/config/week&lt;/code&gt;
endpoint.&lt;/p&gt;</description><content:encoded><![CDATA[<p>For some reason my Roomba 960 decided to fall off the cloud, or at least the official app refuses to see it.</p>
<p>I thankfully already have an instance of <a href="https://github.com/koalazak/rest980">rest980</a> running in my homelab anyhow, and it is still happily chatting with
the bot. And tbh, I might just block cloud access again as having everything local is better anyhow.</p>
<p>In any case, I wanted to disable the schedule currently set on it internally to switch to scheduling stuff from my home automation,
but without the app working I wasn&rsquo;t sure on how. So I went hunting through rest980&rsquo;s source - as the README didn&rsquo;t tell me what
I was looking for - and found that I could program the weekly schedule with some easy <code>curl</code> magic via the <code>/api/local/config/week</code>
endpoint.</p>
<p>Firing off a <code>GET</code> against that, this is the data structure I received:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;cycle&#34;</span>: [
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;none&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;start&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;start&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;start&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;start&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;start&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;none&#34;</span>
</span></span><span style="display:flex;"><span>  ],
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;h&#34;</span>: [
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">9</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">15</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">15</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">15</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">15</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">15</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">9</span>
</span></span><span style="display:flex;"><span>  ],
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;m&#34;</span>: [
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>  ]
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p><code>cycle</code> seems to be the on/off button from Sunday at index 0 to Saturday on index 6. <code>start</code> schedules a cleaning run, <code>none</code> disables it.
<code>h</code> is the hours on which to start each day, and <code>m</code> the minute.</p>
<p>What I wanted to do was to set all of the days to off, and this I achieved with this combined <code>GET</code>/<code>POST</code> call with some <code>jq</code> manipulation in the middle:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl $REST980_URL/api/local/config/week | <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>    jq <span style="color:#e6db74">&#39;.cycle[] = &#34;none&#34;&#39;</span> | <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>    curl --json @- $REST980_URL/api/local/config/week
</span></span></code></pre></div><p>Another problem - hopefully - solved! I&rsquo;ll see tomorrow if this <em>really</em> disabled the schedule 😅 but I&rsquo;m optimistic!</p>
]]></content:encoded></item><item><title>How to use jq to extract new posts from a JSON Feed</title><link>https://foosel.net/til/2023-02-02-how-to-use-jq-to-extract-new-posts-from-a-json-feed/</link><pubDate>Thu, 02 Feb 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2023-02-02-how-to-use-jq-to-extract-new-posts-from-a-json-feed/</guid><description>&lt;p&gt;I&amp;rsquo;m currently looking into ways to automate some stuff around new posts on this page (be it blog or TIL post) directly during the page build on GitHub Actions. For this, I first need to be able to reliably &lt;em&gt;detect&lt;/em&gt; new posts, from a bash run step. So here&amp;rsquo;s how to do that with &lt;a href="https://stedolan.github.io/jq/"&gt;&lt;code&gt;jq&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The idea is to get the current &lt;a href="https://foosel.net/til/how-to-add-json-feed-support-to-hugo/"&gt;&lt;code&gt;feed.json&lt;/code&gt;&lt;/a&gt; prior to publishing the page, and then compare it to the one that was just generated during the build. If there are any differences, we know that there are new posts and can trigger further actions from there.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;m currently looking into ways to automate some stuff around new posts on this page (be it blog or TIL post) directly during the page build on GitHub Actions. For this, I first need to be able to reliably <em>detect</em> new posts, from a bash run step. So here&rsquo;s how to do that with <a href="https://stedolan.github.io/jq/"><code>jq</code></a>.</p>
<p>The idea is to get the current <a href="/til/how-to-add-json-feed-support-to-hugo/"><code>feed.json</code></a> prior to publishing the page, and then compare it to the one that was just generated during the build. If there are any differences, we know that there are new posts and can trigger further actions from there.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Get current feed.json</span>
</span></span><span style="display:flex;"><span>curl -s https://foosel.net/til/feed.json &gt; feed.current.json
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Get new feed.json</span>
</span></span><span style="display:flex;"><span>cp public/til/feed.json feed.next.json
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Compare the two, this is where the magic happens</span>
</span></span><span style="display:flex;"><span>jq --slurpfile current til.current.json --slurpfile next til.next.json -n <span style="color:#e6db74">&#39;$next[0].items - $current[0].items&#39;</span> &gt; til.json
</span></span></code></pre></div><p>Let&rsquo;s go through this <code>jq</code> command there:</p>
<ul>
<li><code>--slurpfile &lt;variable&gt; &lt;file&gt;</code> reads in the given files and makes it accessible as an array contained in the given variable. In this case we read in <code>til.current.json</code> and make it accessible as <code>$current</code>, and also read in <code>til.next.json</code> and make it accessible as <code>$next</code>.</li>
<li><code>-n</code> doesn&rsquo;t wait for input on stdin.</li>
<li><code>'$next[0].items - $current[0].items'</code> subtracts the items from the new feed from the items in the current feed<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</li>
<li><code>&gt; til.json</code> writes the output to <code>til.json</code>.</li>
</ul>
<p><code>til.json</code> will then contain all new items (as long as there weren&rsquo;t more than the feed&rsquo;s item size), can be uploaded as an artifact and then used in further jobs<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>The indexing (e.g. <code>$new[0]</code>) here is needed due to <code>--slurpfile</code> creating an array from the read file. I admittedly need to experiment more with this option to fully understand it, but for the purpose here it works.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>My current goal is to move my announcements on Mastodon for new posts from my NodeRED install got the page build, and also send any webmentions for links contained in new posts as well.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item></channel></rss>