Automated blog posts, with blogger.com, Node-RED and Miniflux

Automated blog posts, with blogger.com, Node-RED and Miniflux

You may have seen some of the posts on https://cybernotdienst.blogspot.com/ with titles like “Whats happening in <something> — News Repost”, these posts are created using a short number of technologies, which I was using anyway and felt like playing a bit around.

  • Node-Red, for those who do not know this, it’s a flow-programming language, it was born within the area or IOT and how to work on the signals and data living there. But I also like that I can chunk my code and give it a natural flow.
    I am using pm2 to enable a better control over node-red (also to make it restart after reboot)
npm install -g --unsafe-perm node-red
npm install pm2@latest -g
pm2 start node-red
  • Miniflux, is a small feedreader, which can live in a docker container. It also comes with an API, so while I was looking on how to manipulate rss feeds with node-red, it came out much easier to simple use that API.
    I simply use miniflux via docker compose.
version: '3'
services:
miniflux:
image: miniflux/miniflux:latest
ports:
- "8050:8080"
depends_on:
- db
environment:
- DATABASE_URL=postgres://miniflux:secret@db/miniflux?sslmode=disable
- RUN_MIGRATIONS=1
- CREATE_ADMIN=1
- ADMIN_USERNAME=admin
- ADMIN_PASSWORD=XXXXX
db:
image: postgres:13
environment:
- POSTGRES_USER=miniflux
- POSTGRES_PASSWORD=XXXXX
volumes:
- miniflux-db:/var/lib/postgresql/data
volumes:
miniflux-db:
  • Javascript, well, this time I force myself to use Javascript instead of my beloved python, let’s call it learning 🙂
  • Blogger.com, Blogger offers an email interface to create blog posts, so it was a natural choice to do that I suppose.
The Node-RED data flow

The flow you see in the picture has two outputs, it will send a shortened blog post (600 characters) to blogger and to myself a full post via email. Let’s explain some of the nodes

  • Timestamp (inject), the blue notes are simply to inject something into the flow and to start this flow. Inject can be used to repeat a task, so every 72h in my case the flow will be started
  • Sleep, sleep is used to wait for 100 seconds in this case
  • The yellow-ish nodes are HTTP requests, I use those in three flavors
  • HTTP get to refresh feeds, basically just sending miniflus the command to refresh all feeds
    PUT http://{{miniflux}}/v1/feeds/refresh
  • HTTP get to get the two feeds from Miniflux
    GET http://{{miniflux}}/v1/feeds/{{feed ID}}/entries
    for our purpose, you might want to do something like this adding some limits and a status, so you don’t repost the same stuff over and over (yes, learning by doing 🙂 )
http://172.18.0.3:8080/v1/feeds/89/entries?limit=10&order=id&direction=asc&status=unread
  • Finally a HTTP put to mark the feeds as read
    PUT http://{{miniflux}}/v1/feeds/{{feed ID}}/mark-all-as-read
  • The light blue boxes are simple send email boxes
  • The dark green debug boxes are the nodes which displays all context data

Node-red simple moves a JavaScriptObject (or JSON ) from node to node as msg. So each node is able to read the msg from the previous node and add data or manipulate data. As an example, the send email node can work with some inputs as data e-mail

Sends the msg.payload as an email, with a subject of msg.topic.

The default message recipient can be configured in the node, if it is left blank it should be set using the msg.to property of the incoming message. If left blank you can also specify any or all of: msg.cc, msg.bcc, msg.replyTo, msg.inReplyTo, msg.references, msg.headers, or msg.priority properties.

For a matter of fact, I am using the msg.topic to set the topic in the node before.

There are only two nodes with a bit of code.

  1. the first function node, this are basically nodes which allow to write javascript which gets executed
    mymsg = JSON.parse(msg.payload)
    return mymsg;

    basically I am only using two lines of code, the JSON received from miniflux is a string, which I need to have as a JSON object
  2. The “Format … Email” — nodes are used to prepare the subject and the body of the email, also because the entries are an array and javascript is may the easiest way I can think of to loop through these
Email = "Disclaimer: I am playing around with Node-Red, Miniflux API, javascript and blogger email. So this are mainly reposts from the original sites :-) all rights and copyright belongs to the owner<h1>Whats happening in Google Cloud - News Repost</h1>";
EmailB = "<br/>";
Formater = (a,b,c) => `<h3>${a}</h3>${b}<p><a href=${c} target=_blank>Read the full story here</a></p><hr>`;
const array1 = msg.entries;

for (let i = 0; i < array1.length; i++) {
EmailT = Formater(array1[i].title,array1[i].content.substring(0,700).concat('...'),array1[i].url);
EmailB = EmailB.concat(EmailT)
}

msg.payload = Email.concat(EmailB);
msg.topic = "Whats happening in Google Cloud - News Repost"
return msg;

Please leave a 👏 if you like and be excellent to each other