A simple way to check if a value is contained in text file.
-
-
Save tim-minter/1e5f25206fadb339293e879f397fa513 to your computer and use it in GitHub Desktop.
A simple way to check if an input matches an entry in a text file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"e025a6f.56cead8","type":"file in","z":"5811904c.b5318","name":"List Of Team Members","filename":"/Users/tim/Desktop/teammembers.txt","format":"utf8","x":764,"y":255,"wires":[["dae4c5b9.339c28","25ee17ce.92e9"]]},{"id":"dae4c5b9.339c28","type":"function","z":"5811904c.b5318","name":"Check for Match","func":"var arrayOfTextEntries = msg.payload.split(\";\");\nvar entryToLookFor = msg.entryToLookFor;\nif (arrayOfTextEntries.indexOf(entryToLookFor)>=1){\n msg.found = true;\n} else {\n msg.found = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":757,"y":404,"wires":[["5ef30987.1894a8"]]},{"id":"dabed1d5.fda648","type":"inject","z":"5811904c.b5318","name":"String to check for","topic":"","payload":"Bob@minions.com","payloadType":"str","repeat":"","crontab":"","once":false,"x":141,"y":256,"wires":[["d6ab0cc1.e24078"]]},{"id":"d6ab0cc1.e24078","type":"function","z":"5811904c.b5318","name":"Format msg for later check","func":"msg.entryToLookFor = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":395,"y":256,"wires":[["e025a6f.56cead8"]]},{"id":"5ef30987.1894a8","type":"debug","z":"5811904c.b5318","name":"","active":true,"console":"false","complete":"found","x":1039,"y":405,"wires":[]},{"id":"25ee17ce.92e9","type":"debug","z":"5811904c.b5318","name":"","active":true,"console":"false","complete":"false","x":1040,"y":255,"wires":[]},{"id":"706f96fc.fe8ec","type":"comment","z":"5811904c.b5318","name":"A simple way to check if an input matches an entry in a text file","info":"","x":277.5,"y":152,"wires":[]},{"id":"2894ccfa.6c994c","type":"comment","z":"5811904c.b5318","name":"Output the contents of the file for testing purposes","info":"So that we can check we have found the file and what it contains","x":1157.5,"y":210,"wires":[]},{"id":"ad8a618e.5ea59","type":"comment","z":"5811904c.b5318","name":"Have we found the string in the file?","info":"","x":1111.5,"y":369,"wires":[]},{"id":"8488d230.48f27","type":"comment","z":"5811904c.b5318","name":"Full path to your text file","info":"eg /Users/tim/Desktop/teammembers.txt\n\nThis flow is written to accept a text file \nwith entries separated by semi-colons eg.\n\nDave@minions.com;Stuart@minions.com;Bob@minions.com;Jerry@minions.com;Carl@minions.com;Kevin@minions.com;Tim@minions.com;Mark@minions.com;Phil@minions.com;John@minions.com;Josh@minions.com;Steve@minions.com;Donny@minions.com;Ken@minions.com;Mike@minions.com;Paul@minions.com;Lance@minions.com;Larry@minions.com;Jorge@minions.com;Tom@minions.com;Norbert@minions.com;Chris@minions.com;Darwin@minions.com;\n\nThe separator is defined and can be changed in the split function within the Check for Match function","x":774.5,"y":212,"wires":[]},{"id":"8f04fe63.b52cc8","type":"comment","z":"5811904c.b5318","name":"Add an entryToLookFor value to the msg object","info":"","x":455.5,"y":213,"wires":[]},{"id":"286bcc2.b1f9334","type":"comment","z":"5811904c.b5318","name":"Convert the string returned by the file node to an array and check if msg.entryToLookFor is in that array","info":"","x":1019.5,"y":448,"wires":[]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Tim
I'am on windows OS.
I would ask you how the file you are using in /Users/tim/Desktop/teammembers.txt is composed.
In the "List of team members" block, i wrote the path to my file: C:\Users\s.bianchi\Desktop\lista.txt
this is a simple txt file with some names on one line.
I inject always a name within the file, what i get at the output is always a false response, but the content of the whole file is correclty displayed.
Could you help me?
Thanks regards.