首页 > 编程语言 >Node-RED中将CSV数据写入txt文件并从文件中读取解析数据

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据

时间:2023-03-22 12:31:24浏览次数:57  
标签:Node edited CSV false name true txt type id


场景

Node-RED简介与Windows上安装、启动和运行示例:

​​Node-RED简介与Windows上安装、启动和运行示例_霸道流氓气质的博客-_nodered windows​​

Node-RED怎样导出导入流程为json文件:

​​Node-RED怎样导出导入流程为json文件_霸道流氓气质的博客-_怎么导出json文件​​

CSV的内容是使用纯文字方式表示的表格资料,第一行是表格的标题,每一列用,隔开。

例如:

Name,height,weight
Joe,170,70
Mary,160,49

怎样将数据存储到txt文件中,需要时从文件中读取并解析获取数据。

注:

博客:​​霸道流氓气质的博客_-C#,架构之路,SpringBoot领域博主​​

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、页面布局

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_UI

2、template节点,输入csv资料

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_UI_02

3、file节点,将csv资料用utf-8编码写入D://file.txt

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_nodered_03

4、file in节点,读取file.txt,输出utf-8的一个字符

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_Ubuntu_04

5、csv节点,剖析csv资料,输入列名,分隔符是逗号,因为第一列是标题列,所以在输入时忽略第一行

输出时选择每行一条信息

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_bc_05

6、解析效果

Node-RED中将CSV数据写入txt文件并从文件中读取解析数据_bc_06

7、json数据

[
{
"id": "f4a4d8eab7935bc8",
"type": "tab",
"label": "流程 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c428312d1f6165d1",
"type": "mqtt-broker",
"name": "mqtt",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "51eee50b4ec9422f",
"type": "ui_group",
"name": "dashboardDemo",
"tab": "29ae4c620f43ee0d",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "29ae4c620f43ee0d",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "a506c767a5c1edbd",
"type": "ui_base",
"theme": {
"name": "theme-light",
"lightTheme": {
"default": "#0094CE",
"baseColor": "#0094CE",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": true,
"reset": false
},
"darkTheme": {
"default": "#097479",
"baseColor": "#097479",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": false
},
"customTheme": {
"name": "Untitled Theme 1",
"default": "#4B7930",
"baseColor": "#4B7930",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
},
"themeState": {
"base-color": {
"default": "#0094CE",
"value": "#0094CE",
"edited": false
},
"page-titlebar-backgroundColor": {
"value": "#0094CE",
"edited": false
},
"page-backgroundColor": {
"value": "#fafafa",
"edited": false
},
"page-sidebar-backgroundColor": {
"value": "#ffffff",
"edited": false
},
"group-textColor": {
"value": "#1bbfff",
"edited": false
},
"group-borderColor": {
"value": "#ffffff",
"edited": false
},
"group-backgroundColor": {
"value": "#ffffff",
"edited": false
},
"widget-textColor": {
"value": "#111111",
"edited": false
},
"widget-backgroundColor": {
"value": "#0094ce",
"edited": false
},
"widget-borderColor": {
"value": "#ffffff",
"edited": false
},
"base-font": {
"value": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"
}
},
"angularTheme": {
"primary": "indigo",
"accents": "blue",
"warn": "red",
"background": "grey",
"palette": "light"
}
},
"site": {
"name": "Node-RED Dashboard",
"hideToolbar": "false",
"allowSwipe": "false",
"lockMenu": "false",
"allowTempTheme": "true",
"dateFormat": "DD/MM/YYYY",
"sizes": {
"sx": 48,
"sy": 48,
"gx": 6,
"gy": 6,
"cx": 6,
"cy": 6,
"px": 0,
"py": 0
}
}
},
{
"id": "248cbbb0.18e794",
"type": "ui_group",
"name": "MyGroup",
"tab": "3f79c420.cfc1bc",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "3f79c420.cfc1bc",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "a0954be5.a7f7e8",
"type": "ui_group",
"name": "MyInput",
"tab": "3f79c420.cfc1bc",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "508bd6f8398ab80f",
"type": "ui_group",
"name": "OpenWeatherMap",
"tab": "3f79c420.cfc1bc",
"order": 3,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "8824dea1.83e31",
"type": "websocket-client",
"path": "ws://localhost:9898/",
"tls": "",
"wholemsg": "false"
},
{
"id": "f9c23ff5.026e",
"type": "file",
"z": "f4a4d8eab7935bc8",
"name": "",
"filename": "D://file.txt",
"appendNewline": true,
"createDir": false,
"overwriteFile": "true",
"encoding": "utf8",
"x": 480,
"y": 180,
"wires": [
[]
]
},
{
"id": "2ebfe992.fdc746",
"type": "inject",
"z": "f4a4d8eab7935bc8",
"name": "",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 240,
"wires": [
[
"cfaafb8.012a108"
]
]
},
{
"id": "cfaafb8.012a108",
"type": "file in",
"z": "f4a4d8eab7935bc8",
"name": "",
"filename": "D://file.txt",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "utf8",
"allProps": false,
"x": 340,
"y": 240,
"wires": [
[
"ee4f2b44.0fc328"
]
]
},
{
"id": "32435220.d9c6ee",
"type": "debug",
"z": "f4a4d8eab7935bc8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.weight",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 680,
"y": 280,
"wires": []
},
{
"id": "ee4f2b44.0fc328",
"type": "csv",
"z": "f4a4d8eab7935bc8",
"name": "",
"sep": ",",
"hdrin": "",
"hdrout": "none",
"multi": "one",
"ret": "\\n",
"temp": "name,height,weight",
"skip": "1",
"strings": true,
"include_empty_strings": "",
"include_null_values": "",
"x": 470,
"y": 240,
"wires": [
[
"f250620f.1071d",
"d9c16f6a.a9d4b",
"32435220.d9c6ee"
]
]
},
{
"id": "f250620f.1071d",
"type": "debug",
"z": "f4a4d8eab7935bc8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.name",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 200,
"wires": []
},
{
"id": "d9c16f6a.a9d4b",
"type": "debug",
"z": "f4a4d8eab7935bc8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload.height",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 240,
"wires": []
},
{
"id": "277f6cb6.89e434",
"type": "template",
"z": "f4a4d8eab7935bc8",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Name,height,weight\nJoe,170,70\nMary,160,49",
"output": "str",
"x": 330,
"y": 180,
"wires": [
[
"f9c23ff5.026e"
]
]
},
{
"id": "f22a93b5.26844",
"type": "inject",
"z": "f4a4d8eab7935bc8",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 190,
"y": 180,
"wires": [
[
"277f6cb6.89e434"
]
]
}
]

标签:Node,edited,CSV,false,name,true,txt,type,id
From: https://blog.51cto.com/BADAOLIUMANGQZ/6142409

相关文章

  • NodeJS 多线程编程
    一、开发环境Node.JSv14.8.0二、快速开始-worker_threadsjs和nodejs一直都是单线程,直到官方推出了worker_threads模块,用来解决CPU密集型计算场景。可以通过......
  • Hbase报错ERROR: KeeperErrorCode = NoNode for /hbase/master
    场景在上面搭建Hadoop和Hbase的基础上,三台服务器全部重启了。再执行hbase的命令时提示:ERROR:KeeperErrorCode=NoNodefor/hbase/master 注:关注公众号霸道的程序猿获......
  • Node-RED简介与Windows上安装、启动和运行示例
    场景Node-RED简介Node-RED是IBM公司开发的一个可视化的编程工具,以满足他们快速连接硬件和设备到Web服务和其他软件的需求,很快发展成为一种通用的物联网编程工具。Node-RED是......
  • Windows上编译github源码方式运行Node-RED,以及离线迁移安装Node-RED
    场景上面是在Windows可以连接外网的情况下安装运行的Node-RED,如果再局域网内的Winserver2012的服务器,没法访问外网,怎样安装运行Node-RED。注:关注公众号霸道的程序猿获取......
  • Node-RED安装图形化节点dashboard实现订阅mqtt主题并在仪表盘中显示温度
    场景上面讲了node-red中获取mqtt数据的调试过程。如果要模拟通过温度传感器的mqtt订阅的主题中获取温度数据并在能显示仪表盘的界面中实时检测刷新数据。node-red支持自定义......
  • CSV
    import pandas as pddf = pd.read_csv('nba.csv')  read_csv( FilePath:文件路径 sep:指定的分隔符,默认是逗号 delimiter:str|None=..., ......
  • 【ASP.NET Core】在node.js上托管Blazor WebAssembly应用
    由于Blazor-WebAssembly是在浏览器中运行的,通常不需要执行服务器代码,只要有个“窝”能托管并提供相关文件的下载即可。所以,当你有一个现成的Blazorwasm项目,没必要用其......
  • 红米手机如何修改安卓目录下的data目录下的txt文件
    两个应用:wpsoffice安卓清理君先用wps编辑保存一个txt的同名文件,当然wps并不能直接保存到安卓目录下这时候使用安卓清理君,删除+移动,就可以达到修改的目的其实安卓自带......
  • node学习四之npm知识点
    1.版本号知识点使用NPM下载和发布代码时都会接触到版本号。NPM使用语义版本号来管理代码,这里简单介绍一下。语义版本号分为X.Y.Z三位,分别代表主版本号、次版本号和补丁版本......
  • NodeJs的模块化和包
    模块化的基本概念什么是模块化?模块化是解决一个复杂问题时,自顶向下逐层把系统划分为若干个模块的过程,编程中,就是遵守一定规则,把一个大文件拆成独立并相互依赖的多个小模......