Working with data in an array

Hey guys and gals.

I'm currently scraping a website to get football stats. I've been able to most of the formatting etc and move the data in to fields but I need a bit of help understanding how to finish it off.

Currently I have this
image

I'd like to split msg.payload[1] up a bit more, I'd like the first number, date, time and team names to be in different parts of the same array.

Also, something else that I'm not able to understand how to do is split msg.payload[2] up. I'd like the number splitting up every two digits in to different parts of the same array.

To clarify can you show exactly what you would like to get out, given the input data you have shown.

As you havent specified exactly what you want to do with the data - i did something I might want...

image

Demo flow (CTRL+I to import)

[{"id":"538c015aa81cdd5b","type":"inject","z":"af952aeaa20f4f97","name":"Norwich-Leads","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\" ENGLAND - PREMIER LEAGUE\",\"12 2021-10-31 14:00-Norwich-Leads\",\"11111111111111111111111111\"]","payloadType":"json","x":2620,"y":140,"wires":[["242e92f4e3188b31"]]},{"id":"29e4ad304101b4a5","type":"inject","z":"af952aeaa20f4f97","name":"Villa-WHam","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\" ENGLAND - PREMIER LEAGUE\",\"X2 2021-10-31 16:30-Aston Villa-West Ham\",\"22222222222222222222222222\"]","payloadType":"json","x":2610,"y":180,"wires":[["242e92f4e3188b31"]]},{"id":"242e92f4e3188b31","type":"function","z":"af952aeaa20f4f97","name":"nice-ification 😉","func":"let [countryLeague, data, id] = msg.payload;\nlet countryLeagueParts = countryLeague.split(\" - \");\nlet country = countryLeagueParts[0].trim();\nlet league = countryLeagueParts[1].trim();\nlet number = (data.slice(0,2));\nlet date = new Date(data.slice(3,19));\nlet teams = data.slice(20).split(\"-\");\n\nmsg.payload = {\n    country,\n    league,\n    number,\n    date,\n    homeTeam: teams[0],\n    awayTeam: teams[1],\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2800,"y":160,"wires":[["04848441442b51d5"]]},{"id":"04848441442b51d5","type":"debug","z":"af952aeaa20f4f97","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2810,"y":220,"wires":[]}]

That's almost perfect thankyou. Apologies for not giving an example of what I wanted to do with the data, but you got it correct anyways! :slight_smile:

image

One last thing that I'm trying to attempt is to split the last number up also into different objects. So for msg.payload[2] I'd like that splitting up every 2 numbers into separate objects.

For eg:

country: "England"
league: "Premier League"
number: "12"
date: "2021-10-31T14:00:00.000Z"
homeTeam: "Norwich"
awayTeam: "Leeds"
home: "42"
draw: "26"
away: "32"
HT1: "26"
HTX: "46"
HT2: "28"
o1.5: "89"
o2.5: "67"
o3.5: "38"
bts: "57"
ots: "43"

I hope that makes sense

Here is similar using a change node and JSONata expression.You can converted string number to numbers also if you need to.

[{"id":"33d085d8.0d8352","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.(\t   $bits0 := $split($[0], \"-\").$trim($);\t   $bits1 := [\t       $append(\t           $split($[1], /-| /)[[0..4]],\t           $split($[1], \"-\")[[3,4]]\t       )\t   ].$trim($);\t   $bits2 := [$match($[2], /\\d\\d/)].match;\t   {\t       \"country\": $bits0[0],\t       \"league\": $bits0[1],\t       \"number\": $bits1[0],\t       \"date\": $bits1[1] & \"-\" & $bits1[2] & \"-\" & $bits1[3],\t       \"time\": $bits1[4],\t       \"timestamp\":  $bits1[1] & \"-\" & $bits1[2] & \"-\" & $bits1[3] &\"T\" & $bits1[4] &  \":00.000Z\",\t       \"homeTeam\": $bits1[5],\t       \"awayTeam\": $bits1[6],\t       \"home\": $bits2[0],\t       \"draw\": $bits2[1],\t       \"away\": $bits2[2],\t       \"HT1\": $bits2[3],\t       \"HTX\": $bits2[4],\t       \"HT2\": $bits2[5],\t       \"o1.5\": $bits2[6],\t       \"o2.5\": $bits2[7],\t       \"o3.5\": $bits2[8],\t       \"bts\": $bits2[9],\t       \"ots\": $bits2[10]\t       }\t\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":3860,"wires":[["1c48acb2.d89fd3"]]},{"id":"f50918bd.89d3f8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[\"  england - premier league\",\"12 2021-10-31 14:00-norwic-leeds\",\"2435465768798975642858\"],[\" england - premier league\",\"12 2021-10-31 14:00-astoin villa-leeds\",\"2435465768798975642858\"],[\" england - premier league\",\"12 2021-10-31 14:00-brighton-leeds\",\"2435465768798975642858\"]]","payloadType":"json","x":160,"y":3840,"wires":[["33d085d8.0d8352"]]},{"id":"1c48acb2.d89fd3","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":3880,"wires":[]}]

Input

[["  england - premier league","12 2021-10-31 14:00-norwic-leeds","2435465768798975642858"],[" england - premier league","12 2021-10-31 14:00-astoin villa-leeds","2435465768798975642858"],[" england - premier league","12 2021-10-31 14:00-brighton-leeds","2435465768798975642858"]]

Output

[{"country":"england","league":"premier league","number":"12","date":"2021-10-31","time":"14:00","timestamp":"2021-10-31T14:00:00.000Z","homeTeam":"norwic","awayTeam":"leeds","home":"24","draw":"35","away":"46","HT1":"57","HTX":"68","HT2":"79","o1.5":"89","o2.5":"75","o3.5":"64","bts":"28","ots":"58"},{"country":"england","league":"premier league","number":"12","date":"2021-10-31","time":"14:00","timestamp":"2021-10-31T14:00:00.000Z","homeTeam":"astoin villa","awayTeam":"leeds","home":"24","draw":"35","away":"46","HT1":"57","HTX":"68","HT2":"79","o1.5":"89","o2.5":"75","o3.5":"64","bts":"28","ots":"58"},{"country":"england","league":"premier league","number":"12","date":"2021-10-31","time":"14:00","timestamp":"2021-10-31T14:00:00.000Z","homeTeam":"brighton","awayTeam":"leeds","home":"24","draw":"35","away":"46","HT1":"57","HTX":"68","HT2":"79","o1.5":"89","o2.5":"75","o3.5":"64","bts":"28","ots":"58"}]

expression

$$.payload.(
   $bits0 := $split($[0], "-").$trim($);
   $bits1 := [
       $append(
           $split($[1], /-| /)[[0..4]],
           $split($[1], "-")[[3,4]]
       )
   ].$trim($);
   $bits2 := [$match($[2], /\d\d/)].match;
   {
       "country": $bits0[0],
       "league": $bits0[1],
       "number": $bits1[0],
       "date": $bits1[1] & "-" & $bits1[2] & "-" & $bits1[3],
       "time": $bits1[4],
       "timestamp":  $bits1[1] & "-" & $bits1[2] & "-" & $bits1[3] &"T" & $bits1[4] &  ":00.000Z",
       "homeTeam": $bits1[5],
       "awayTeam": $bits1[6],
       "home": $bits2[0],
       "draw": $bits2[1],
       "away": $bits2[2],
       "HT1": $bits2[3],
       "HTX": $bits2[4],
       "HT2": $bits2[5],
       "o1.5": $bits2[6],
       "o2.5": $bits2[7],
       "o3.5": $bits2[8],
       "bts": $bits2[9],
       "ots": $bits2[10]
       }

)

Thanks for the help.

Almost there with this option.

My messages are one game per message, so all the info is in one array per message rather than multiple arrays per message (at least I think that's how I need to explain it)

So my input would be slightly different

This is mine

[
    "  england - premier league",
    "12 2021-10-31 14:00-norwic-leeds",
    "2435465768798975642858"
]

This is yours

[
    [
        "  england - premier league",
        "12 2021-10-31 14:00-norwic-leeds",
        "2435465768798975642858"
    ]
]

So the diff is as below

image

Sorry, I have no idea how to change your code to what I need for my input vs yours.

Sorry for error , but mistakes happen when copying from image. Best to paste text, so no mistakes and easier in long run.

(
   $bits0 := $split(payload[0], "-").$trim($);
   $bits1 := [
       $append(
           $split(payload[1], /(-|\s)+/)[[0..4]],
           $split(payload[1], "-")[[3,4]]
       )
   ].$trim($);
   $bits2 := [$match(payload[2], /\d\d/)].match;
   {
       "country": $bits0[0],
       "league": $bits0[1],
       "number": $bits1[0],
       "date": $bits1[1] & "-" & $bits1[2] & "-" & $bits1[3],
       "time": $bits1[4],
       "timestamp":  $bits1[1] & "-" & $bits1[2] & "-" & $bits1[3] &"T" & $bits1[4] &  ":00.000Z",
       "homeTeam": $bits1[5],
       "awayTeam": $bits1[6],
       "home": $bits2[0],
       "draw": $bits2[1],
       "away": $bits2[2],
       "HT1": $bits2[3],
       "HTX": $bits2[4],
       "HT2": $bits2[5],
       "o1.5": $bits2[6],
       "o2.5": $bits2[7],
       "o3.5": $bits2[8],
       "bts": $bits2[9],
       "ots": $bits2[10]
       }

)

Here is edited expression. You will see payload has moved to where $[0] $[1] and $[2] used to be.

Sorry I'm not following your example.

This is what I have so far

[{"id":"d88dd470.0ac7b8","type":"inject","z":"ffe44f33e5843155","name":"make request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payloadType":"date","x":120,"y":40,"wires":[["874a3d4e.9b666"]]},{"id":"874a3d4e.9b666","type":"http request","z":"ffe44f33e5843155","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.statarea.com/predictions/date/2021-11-01/starttime","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":120,"y":90,"wires":[["90243cc1.87edc"]]},{"id":"90243cc1.87edc","type":"html","z":"ffe44f33e5843155","name":"EPL","property":"payload","outproperty":"payload","tag":"#\\30 10827","ret":"text","as":"multi","x":290,"y":40,"wires":[["db4a77d111714b53"]]},{"id":"db4a77d111714b53","type":"change","z":"ffe44f33e5843155","name":"Change","rules":[{"t":"change","p":"payload","pt":"msg","from":"your","fromt":"str","to":",your","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"prediction","fromt":"str","to":"prediction,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"LEAGUE","fromt":"str","to":"LEAGUE,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"TIP","fromt":"str","to":"TIP,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1X2H1HXH21.52.53.5BTSOTS","fromt":"str","to":",1X2H1HXH21.52.53.5BTSOTS,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"close","fromt":"str","to":",close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":90,"wires":[["b45b7cdf7ba8e354"]]},{"id":"b45b7cdf7ba8e354","type":"change","z":"ffe44f33e5843155","name":"Build array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$split(payload,',')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":90,"wires":[["600f6ed3a3db3390"]]},{"id":"600f6ed3a3db3390","type":"change","z":"ffe44f33e5843155","name":"Change","rules":[{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[2]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"change","p":"payload[0]","pt":"msg","from":"ENGLAND","fromt":"str","to":"England","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"PREMIER LEAGUE","fromt":"str","to":"Premier League","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":40,"wires":[["242e92f4e3188b31","a36ea0445dfcfdab"]]},{"id":"242e92f4e3188b31","type":"function","z":"ffe44f33e5843155","name":"","func":"let [countryLeague, data, id] = msg.payload;\nlet countryLeagueParts = countryLeague.split(\" - \");\nlet country = countryLeagueParts[0].trim();\nlet league = countryLeagueParts[1].trim();\nlet number = (data.slice(0,2));\nlet date = new Date(data.slice(3,19));\nlet teams = data.slice(20).split(\"-\");\n\nmsg.payload = {\n    country,\n    league,\n    number,\n    date,\n    homeTeam: teams[0],\n    awayTeam: teams[1],\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":40,"wires":[["04848441442b51d5"]]},{"id":"04848441442b51d5","type":"debug","z":"ffe44f33e5843155","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":940,"y":40,"wires":[]},{"id":"a36ea0445dfcfdab","type":"change","z":"ffe44f33e5843155","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t   $bits0 := $split(payload[0], \"-\").$trim($);\t   $bits1 := [\t       $append(\t           $split(payload[1], /-| /)[[0..4]],\t           $split(payload[1], \"-\")[[3,4]]\t       )\t   ].$trim($);\t   $bits2 := [$match(payload[2], /\\d\\d/)].match;\t   {\t       \"home\": $bits2[0],\t       \"draw\": $bits2[1],\t       \"away\": $bits2[2],\t       \"HT1\": $bits2[3],\t       \"HTX\": $bits2[4],\t       \"HT2\": $bits2[5],\t       \"o1.5\": $bits2[6],\t       \"o2.5\": $bits2[7],\t       \"o3.5\": $bits2[8],\t       \"bts\": $bits2[9],\t       \"ots\": $bits2[10]\t       }\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":110,"wires":[["609933cde0b38546"]]},{"id":"609933cde0b38546","type":"debug","z":"ffe44f33e5843155","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":110,"wires":[]}]

Which gives this

But I'd like it in this format but only in one message. Your previous example through out this, everything above homeTeam: seems to be mangled somehow

image

Just stick with JavaScript, its easier :wink: ...

[{"id":"f77a4f9882128f33","type":"inject","z":"af952aeaa20f4f97","name":"make request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payloadType":"date","x":2490,"y":440,"wires":[["80e7042fb5cb18a1"]]},{"id":"80e7042fb5cb18a1","type":"http request","z":"af952aeaa20f4f97","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.statarea.com/predictions/date/2021-11-01/starttime","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2670,"y":440,"wires":[["f7c6a7806f5a3f1d"]]},{"id":"f7c6a7806f5a3f1d","type":"html","z":"af952aeaa20f4f97","name":"EPL","property":"payload","outproperty":"payload","tag":"#\\30 10827","ret":"text","as":"multi","x":2830,"y":440,"wires":[["3a6afb35e994f108"]]},{"id":"3a6afb35e994f108","type":"change","z":"af952aeaa20f4f97","name":"Change","rules":[{"t":"change","p":"payload","pt":"msg","from":"your","fromt":"str","to":",your","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"prediction","fromt":"str","to":"prediction,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"LEAGUE","fromt":"str","to":"LEAGUE,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"TIP","fromt":"str","to":"TIP,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1X2H1HXH21.52.53.5BTSOTS","fromt":"str","to":",1X2H1HXH21.52.53.5BTSOTS,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"close","fromt":"str","to":",close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3020,"y":440,"wires":[["8f7cc712f4c3b994"]]},{"id":"8f7cc712f4c3b994","type":"change","z":"af952aeaa20f4f97","name":"Build array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$split(payload,',')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":2490,"y":500,"wires":[["19524db83822301c"]]},{"id":"40f4a17deb03a458","type":"debug","z":"af952aeaa20f4f97","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":3070,"y":500,"wires":[]},{"id":"19524db83822301c","type":"change","z":"af952aeaa20f4f97","name":"Change","rules":[{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[2]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"change","p":"payload[0]","pt":"msg","from":"ENGLAND","fromt":"str","to":"England","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"PREMIER LEAGUE","fromt":"str","to":"Premier League","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2660,"y":500,"wires":[["2d89cc6b0c38118f"]]},{"id":"2d89cc6b0c38118f","type":"function","z":"af952aeaa20f4f97","name":"nice-ification 😉","func":"let [countryLeague, data, stats] = msg.payload;\nlet countryLeagueParts = countryLeague.split(\" - \");\nlet country = countryLeagueParts[0].trim();\nlet league = countryLeagueParts[1].trim();\nlet number = (data.slice(0,2));\nlet date = new Date(data.slice(3,19));\nlet teams = data.slice(20).split(\"-\");\nlet statistics = stats.match(/.{1,2}/g)\nmsg.payload = {\n    country,\n    league,\n    number,\n    date,\n    homeTeam: teams[0],\n    awayTeam: teams[1],\n    statistics: {\n        \"home\": +statistics[0],\n        \"draw\": +statistics[1],\n        \"away\": +statistics[2],\n        \"HT1\": +statistics[3],\n        \"HTX\": +statistics[4],\n        \"HT2\": +statistics[5],\n        \"o1.5\": +statistics[6],\n        \"o2.5\": +statistics[7],\n        \"o3.5\": +statistics[8],\n        \"bts\": +statistics[9],\n        \"ots\": +statistics[10]\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2860,"y":500,"wires":[["40f4a17deb03a458"]]}]

Thankyou! :slight_smile:

Try this as some white space was not space

[{"id":"d88dd470.0ac7b8","type":"inject","z":"b779de97.b1b46","name":"make request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payloadType":"date","x":140,"y":4900,"wires":[["874a3d4e.9b666"]]},{"id":"874a3d4e.9b666","type":"http request","z":"b779de97.b1b46","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.statarea.com/predictions/date/2021-11-01/starttime","tls":"","persist":false,"proxy":"","authType":"","x":140,"y":4950,"wires":[["a4684d13.279d9"]]},{"id":"a4684d13.279d9","type":"html","z":"b779de97.b1b46","name":"EPL","property":"payload","outproperty":"payload","tag":"div>[id='010827']","ret":"text","as":"multi","x":330,"y":4900,"wires":[["db4a77d111714b53"]]},{"id":"db4a77d111714b53","type":"change","z":"b779de97.b1b46","name":"Change","rules":[{"t":"change","p":"payload","pt":"msg","from":"your","fromt":"str","to":",your","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"prediction","fromt":"str","to":"prediction,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"LEAGUE","fromt":"str","to":"LEAGUE,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"TIP","fromt":"str","to":"TIP,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1X2H1HXH21.52.53.5BTSOTS","fromt":"str","to":",1X2H1HXH21.52.53.5BTSOTS,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"close","fromt":"str","to":",close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":4950,"wires":[["b45b7cdf7ba8e354"]]},{"id":"b45b7cdf7ba8e354","type":"change","z":"b779de97.b1b46","name":"Build array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$split(payload,',')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":4950,"wires":[["600f6ed3a3db3390"]]},{"id":"600f6ed3a3db3390","type":"change","z":"b779de97.b1b46","name":"Change","rules":[{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[2]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"change","p":"payload[0]","pt":"msg","from":"ENGLAND","fromt":"str","to":"England","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"PREMIER LEAGUE","fromt":"str","to":"Premier League","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":4900,"wires":[["463609ef.34eb38","242e92f4e3188b31"]]},{"id":"463609ef.34eb38","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t   $bits0 := $split(payload[0], \"-\").$trim($);\t   $bits1 := [\t       $append(\t           $split(payload[1], /(-|\\s)+/)[[0..4]],\t           $split(payload[1], \"-\")[[3,4]]\t       )\t   ].$trim($);\t   $bits2 := [$match(payload[2], /\\d\\d/)].match;\t   {\t       \"country\": $bits0[0],\t       \"league\": $bits0[1],\t       \"number\": $bits1[0],\t       \"date\": $bits1[1] & \"-\" & $bits1[2] & \"-\" & $bits1[3],\t       \"time\": $bits1[4],\t       \"timestamp\":  $bits1[1] & \"-\" & $bits1[2] & \"-\" & $bits1[3] &\"T\" & $bits1[4] &  \":00.000Z\",\t       \"homeTeam\": $bits1[5],\t       \"awayTeam\": $bits1[6],\t       \"home\": $bits2[0],\t       \"draw\": $bits2[1],\t       \"away\": $bits2[2],\t       \"HT1\": $bits2[3],\t       \"HTX\": $bits2[4],\t       \"HT2\": $bits2[5],\t       \"o1.5\": $bits2[6],\t       \"o2.5\": $bits2[7],\t       \"o3.5\": $bits2[8],\t       \"bts\": $bits2[9],\t       \"ots\": $bits2[10]\t       }\t\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":4960,"wires":[["609933cde0b38546"]]},{"id":"242e92f4e3188b31","type":"function","z":"b779de97.b1b46","name":"","func":"let [countryLeague, data, id] = msg.payload;\nlet countryLeagueParts = countryLeague.split(\" - \");\nlet country = countryLeagueParts[0].trim();\nlet league = countryLeagueParts[1].trim();\nlet number = (data.slice(0,2));\nlet date = new Date(data.slice(3,19));\nlet teams = data.slice(20).split(\"-\");\n\nmsg.payload = {\n    country,\n    league,\n    number,\n    date,\n    homeTeam: teams[0],\n    awayTeam: teams[1],\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":4900,"wires":[["04848441442b51d5"]]},{"id":"609933cde0b38546","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":4970,"wires":[]},{"id":"04848441442b51d5","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":4900,"wires":[]}]

That worked great for that data, it seems there's a slight variation in the input text for different games, this is for the number see at the start of the second line in the array. This number could be either 1 or 2 or X or 1X or X2

This is what I currently have which is missing the date

[{"id":"f77a4f9882128f33","type":"inject","z":"ffe44f33e5843155","name":"make request","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payloadType":"date","x":380,"y":570,"wires":[["80e7042fb5cb18a1"]]},{"id":"80e7042fb5cb18a1","type":"http request","z":"ffe44f33e5843155","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://www.statarea.com/predictions/date/2021-11-05/starttime","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":560,"y":570,"wires":[["f7c6a7806f5a3f1d"]]},{"id":"f7c6a7806f5a3f1d","type":"html","z":"ffe44f33e5843155","name":"EPL","property":"payload","outproperty":"payload","tag":"#\\30 10827","ret":"text","as":"multi","x":720,"y":570,"wires":[["3a6afb35e994f108"]]},{"id":"3a6afb35e994f108","type":"change","z":"ffe44f33e5843155","name":"Change","rules":[{"t":"change","p":"payload","pt":"msg","from":"your","fromt":"str","to":",your","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"prediction","fromt":"str","to":"prediction,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"LEAGUE","fromt":"str","to":"LEAGUE,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"TIP","fromt":"str","to":"TIP,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1X2H1HXH21.52.53.5BTSOTS","fromt":"str","to":",1X2H1HXH21.52.53.5BTSOTS,","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"close","fromt":"str","to":",close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":570,"wires":[["8f7cc712f4c3b994"]]},{"id":"8f7cc712f4c3b994","type":"change","z":"ffe44f33e5843155","name":"Build array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$split(payload,',')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":630,"wires":[["19524db83822301c"]]},{"id":"40f4a17deb03a458","type":"debug","z":"ffe44f33e5843155","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":630,"wires":[]},{"id":"19524db83822301c","type":"change","z":"ffe44f33e5843155","name":"Change","rules":[{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[0]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[1]","pt":"msg"},{"t":"delete","p":"payload[2]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"delete","p":"payload[3]","pt":"msg"},{"t":"change","p":"payload[0]","pt":"msg","from":"ENGLAND","fromt":"str","to":"England","tot":"str"},{"t":"change","p":"payload[0]","pt":"msg","from":"PREMIER LEAGUE","fromt":"str","to":"Premier League","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":630,"wires":[["2d89cc6b0c38118f","8a86d95287f3cbc4"]]},{"id":"2d89cc6b0c38118f","type":"function","z":"ffe44f33e5843155","name":"nice-ification 😉","func":"let [countryLeague, data, stats] = msg.payload;\nlet countryLeagueParts = countryLeague.split(\" - \");\nlet country = countryLeagueParts[0].trim();\nlet league = countryLeagueParts[1].trim();\nlet number = (data.slice(0,2));\nlet date = new Date(data.slice(3,19));\nlet teams = data.slice(20).split(\"-\");\nlet statistics = stats.match(/.{1,2}/g)\nmsg.payload = {\n    country,\n    league,\n    number,\n    date,\n    homeTeam: teams[0],\n    awayTeam: teams[1],\n    statistics: {\n        \"home\": +statistics[0],\n        \"draw\": +statistics[1],\n        \"away\": +statistics[2],\n        \"HT1\": +statistics[3],\n        \"HTX\": +statistics[4],\n        \"HT2\": +statistics[5],\n        \"o1.5\": +statistics[6],\n        \"o2.5\": +statistics[7],\n        \"o3.5\": +statistics[8],\n        \"bts\": +statistics[9],\n        \"ots\": +statistics[10]\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":630,"wires":[["40f4a17deb03a458"]]},{"id":"8a86d95287f3cbc4","type":"debug","z":"ffe44f33e5843155","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":680,"wires":[]}]

Input

array[3]
0: " England - Premier League"
1: "1 2021-11-05 20:00-Southampton-Aston Villa"
2: "4725283343248257395743"

Output

object
country: "England"
league: "Premier League"
number: "1 "
date: null
homeTeam: "outhampton"
awayTeam: "Aston Villa"
statistics: object
home: 47
draw: 25
away: 28
HT1: 33
HTX: 43
HT2: 24
o1.5: 82
o2.5: 57
o3.5: 39
bts: 57
ots: 43

The problem I see here is the first number on line 2 of the imput, on the previous input this was two digits long, this time it's only one so I'm guessing that it breaks the rest of the formatting for this line?

It can be solved fairly simply - I don't have time right now but will try to help out later tonight

1 Like

Try changing the function code to this...

const [countryLeague, data, stats] = msg.payload;
const countryLeagueParts = countryLeague.split(" - ");
const dataParts = data.match(/(.+?)\W([\d-]+\W[\d:]+)-(.+?)-(.+)/);
const statistics = stats.match(/.{1,2}/g)
msg.payload = {
    country: countryLeagueParts[0].trim(),
    league: countryLeagueParts[1].trim(),
    number: dataParts[1],
    date: new Date(dataParts[2]),
    homeTeam: dataParts[3],
    awayTeam: dataParts[4],
    statistics: {
        "home": +statistics[0],
        "draw": +statistics[1],
        "away": +statistics[2],
        "HT1": +statistics[3],
        "HTX": +statistics[4],
        "HT2": +statistics[5],
        "o1.5": +statistics[6],
        "o2.5": +statistics[7],
        "o3.5": +statistics[8],
        "bts": +statistics[9],
        "ots": +statistics[10]
    }
}
return msg;
1 Like

Perfect thank you.

That works across a whole bunch of games and leagues! :slight_smile:

My next task is learning how to write all of this to a database and calling the details in to Telegram!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.