# Pull times from a file and write to another

**URL:** <https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377>\
**Category:** General\
**Tags:** home-assistant\
**Created:** [23 August 2024 20:29 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377 "2024-08-23T20:29:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![om3rx](https://avatars.discourse-cdn.com/v4/letter/o/4bbf92/32.png) [@om3rx](https://discourse.nodered.org/u/om3rx)\
**Post date:** [23 August 2024 20:29 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/1 "2024-08-23T20:29:40Z")

</div>

Hello everyone,

I'm looking for help, I had previously a working node that was pulling 6 times every day on a website and writing on a file called timex.txt The website implemented some security I'm unable to query but the webpage has option to export the full calendar year with the 6 times daily. Can someone assist me creating a node?

Current setup which stopped working

```auto
[{"id":"25204c8da7c94154","type":"tab","label":"Diyanet Namaz Vakitleri","disabled":false,"info":"","env":[]},{"id":"af97dd1eb36b36c8","type":"inject","z":"25204c8da7c94154","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"15 00 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":40,"wires":[["b9bd128be5681bc5"]]},{"id":"b9bd128be5681bc5","type":"http request","z":"25204c8da7c94154","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://namazvakitleri.diyanet.gov.tr/tr-TR/9132/montreal-icin-namaz-vakti","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"User-Agent","keyValue":"","valueType":"other","valueValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0"}],"x":250,"y":100,"wires":[["c1d11906950c26ff"]]},{"id":"c1d11906950c26ff","type":"html","z":"25204c8da7c94154","name":"html select","property":"payload","outproperty":"payload","tag":"td","ret":"text","as":"single","chr":"","x":390,"y":160,"wires":[["1a4a36bc8fda9e9c"]]},{"id":"1a4a36bc8fda9e9c","type":"template","z":"25204c8da7c94154","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"time\":[\"{{payload.2}}\",\"{{payload.3}}\",\"{{payload.4}}\",\"{{payload.5}}\",\"{{payload.6}}\",\"{{payload.7}}\"],\"date\":\"{{payload.0}}\"}","output":"str","x":520,"y":220,"wires":[["f127216b9eb82840"]]},{"id":"f127216b9eb82840","type":"file","z":"25204c8da7c94154","name":"","filename":"/homeassistant/times.txt","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":690,"y":280,"wires":[[]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3764237bfc76d40fd5f023d3565c438d6ab8cb4.png)

Because the website is now secure, I exported the calendar to cvs file which is in this format

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/3867bb5ff11da1198ecfdedc1d031d9f55e0a5ae.png)

I would like to have a node that look on this file everyday at 00:01 and take the 6 hours and write in timex.txt file

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 August 2024 20:36 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/2 "2024-08-23T20:36:59Z")

</div>

The flow you posted is corrupt, due to not following guide to posting code/flows..

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

Also please supply the csv file in text format, you do not need to post the whole csv text the first 4-5 lines would be enough.

An example with limited csv data

```auto
[{"id":"63999ac0c1ecc5d5","type":"debug","z":"d1395164b4eec73e","name":"debug 265","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":80,"wires":[]},{"id":"1a4a36bc8fda9e9c","type":"template","z":"d1395164b4eec73e","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"time\":[\"{{payload.fajr}}\",\"{{payload.sun}}\",\"date\":\"{{payload.date}}\"}","output":"str","x":500,"y":80,"wires":[["63999ac0c1ecc5d5"]]},{"id":"af97dd1eb36b36c8","type":"inject","z":"d1395164b4eec73e","name":"run yearly ","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":20,"wires":[["8792f21b0cabe252"]]},{"id":"8792f21b0cabe252","type":"template","z":"d1395164b4eec73e","name":"simulater csv file in output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Calender Date,Fajr,Sun\n23.08.2024,05:01,07:02\n24.08.2024,05.23,07:34\n25.08.2024,05:45,07:45","output":"str","x":340,"y":20,"wires":[["2c8921423c576b68"]]},{"id":"2c8921423c576b68","type":"csv","z":"d1395164b4eec73e","name":"","sep":",","hdrin":false,"hdrout":"none","multi":"one","ret":"\\n","temp":"date,fajr,sun","skip":"1","strings":false,"include_empty_strings":"","include_null_values":"","x":530,"y":20,"wires":[["0a9078ed240fb210"]]},{"id":"0a9078ed240fb210","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"parts.type","pt":"msg","to":"object","tot":"str"},{"t":"set","p":"parts.key","pt":"msg","to":"payload.date","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":20,"wires":[["27a60f01181bf304"]]},{"id":"27a60f01181bf304","type":"join","z":"d1395164b4eec73e","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":830,"y":20,"wires":[["2095f40f6ace247e"]]},{"id":"2095f40f6ace247e","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"prayer_dates","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":20,"wires":[[]]},{"id":"9e9a80858efdd5da","type":"inject","z":"d1395164b4eec73e","name":"run nightly","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":80,"wires":[["cbdff60b23e58eed"]]},{"id":"cbdff60b23e58eed","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"date","pt":"msg","to":"$moment().format(\"DD.MM.YYYY\")","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"prayer_dates[msg.date]","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":80,"wires":[["1a4a36bc8fda9e9c"]]}]

```

---

<div class="post-metadata">

**Author:** ![om3rx](https://avatars.discourse-cdn.com/v4/letter/o/4bbf92/32.png) [@om3rx](https://discourse.nodered.org/u/om3rx)\
**Post date:** [23 August 2024 21:59 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/3 "2024-08-23T21:59:22Z")

</div>

I updated the initial post above.

this is the content of csv file, I just took the first 4lines.

| Calendar Date | Fajr | Sun | Dhuhr | Asr | Maghrib | Isha |
| --- | --- | --- | --- | --- | --- | --- |
| 01.01.2024 | 05:47 | 07:27 | 12:02 | 14:07 | 16:27 | 17:56 |
| 02.01.2024 | 05:47 | 07:27 | 12:03 | 14:08 | 16:28 | 17:57 |
| 03.01.2024 | 05:47 | 07:27 | 12:03 | 14:08 | 16:29 | 17:58 |
| 04.01.2024 | 05:47 | 07:27 | 12:04 | 14:09 | 16:30 | 17:59 |

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 August 2024 22:11 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/4 "2024-08-23T22:11:13Z")

</div>

We would require the exact format of the csv file, not a forum markdown equivalent.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 August 2024 22:34 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/5 "2024-08-23T22:34:19Z")

</div>

> [@om3rx](#):
>
> `Diyanet Namaz Vakitleri`

There are of course APIs to report prayer times, which might be a viable alternative to downloading and parsing a CSV file.

---

<div class="post-metadata">

**Author:** ![om3rx](https://avatars.discourse-cdn.com/v4/letter/o/4bbf92/32.png) [@om3rx](https://discourse.nodered.org/u/om3rx)\
**Post date:** [23 August 2024 22:43 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/6 "2024-08-23T22:43:35Z")

</div>

> [@jbudd](#):
>
> APIs

I couldn't find something to report from the website I'm using..

---

<div class="post-metadata">

**Author:** ![om3rx](https://avatars.discourse-cdn.com/v4/letter/o/4bbf92/32.png) [@om3rx](https://discourse.nodered.org/u/om3rx)\
**Post date:** [23 August 2024 23:24 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/7 "2024-08-23T23:24:19Z")

</div>

Hi E1cid, thanks the example of code you gave above worked. I just modified my cvs file to have all in one cell with commas and modified your code to have the 6columns..

Tarih,İmsak,Güneş,Öğle,İkindi,Akşam,Yatsı  
01.01.2024,05:47,07:27,12:02,14:07,16:27,17:56  
02.01.2024,05:47,07:27,12:03,14:08,16:28,17:57  
03.01.2024,05:47,07:27,12:03,14:08,16:29,17:58

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 September 2024 23:25 UTC](https://discourse.nodered.org/t/pull-times-from-a-file-and-write-to-another/90377/8 "2024-09-06T23:25:11Z")

</div>

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