How to insert a Timestamp in a CSV for each parsed tweet

#1

Dear community,

i am new to Node Red and hope that my question is not too obvious. However, i did not find any thread, related to my current challange.

So what i am currently doing is a twitter parser to CSV. Parsing from twitter to a csv file works like a charm, but the tweets are parsed without timestamps. Could you kindly help me to insert an additional timestamp in an extra column in the created csv file?

Attached you can see the current build of my flow:

Thank you a lot in advance for any help.

Kind Regards

D. Petrik

#2

You posted this in core development which if you read the description is for developers helping to write to core part of Node-RED. I’ve therefore moved it to the more appropriate #general

#3

You should be able to get the current time stamp using the contrib-moment node, or by using javascript in a function node that you can then add to the message object for passing to a csv file. Have a go and if you get stuck come back and show us where you’ve got to

#4

Here is a function node that will show you how to build up the string required to be put into the file

var topic = msg.topic;
if (msg.payload === "1") {
    var p = "On";
    } 
else if (msg.payload === "0") { 
    var p = "Off";
    }
else var p = "Unknown";

var d = flow.get("MyDateTime") || "0";
//var myCount = flow.get("count", storeName);

//create message to write to the log file
var payload1 = (d + " Tank Pump is " + p + " Topic is: " + msg.topic);
//Store message so it can be output on output 1
var msg1 = { payload:payload1 };

//Create 2nd message for screen writing on scrolling table
var payload2 = (d + " Tank Pump is " + p);
//Store message so it can be output on output 2
var msg2 = { payload:payload2 };

if (p == "On") {
var msg3 = { payload:'<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i>' };
}

if (p == "Off") {
var msg3 = { payload:'<i class="fa fa-stop-circle-o fa-3x fa-fw"></i>' };
}

//End Function and return two messages on two outputs
return [msg1, msg2, msg3,];

I use the Contrib moment function to build a Global variable that is stored in another function and then referenced in here

Craig

#5

I use node-red-contrib-simpletime to add date/time info to msgs

#6

Thank you guys for the suggestions and for the moving the thread to the general section. My bad.

I see - there is no predefined node for this - only the possibility to write a function. I will try out the node and the fuction code and report :slight_smile:

Kind Regards

#7

Thanks guys.

I have figured it out and inserted the following code between the twitter input node and the tweets node:

var tweets = msg.payload;
var TweetPayload = {};
TweetPayload.date = new Date().toString();
TweetPayload.tweet = tweets;
msg.payload = TweetPayload;
return msg;

I failed somehow to use the node-red-contrib-simpletime :-X I assume that it also requires additional code to get it work.

Kind Regards