Skip to content

Instantly share code, notes, and snippets.

@remisarrailh
Created June 3, 2019 10:52
Show Gist options
  • Save remisarrailh/77bba4d9a31b1f9488c7311ea875903d to your computer and use it in GitHub Desktop.
Save remisarrailh/77bba4d9a31b1f9488c7311ea875903d to your computer and use it in GitHub Desktop.
[
{
"id": "e50cb0c0.87ac9",
"type": "tab",
"label": "Bot Discord",
"disabled": false,
"info": ""
},
{
"id": "64569321.c6707c",
"type": "discordSendMessage",
"z": "e50cb0c0.87ac9",
"name": "Send to Discord",
"channel": "",
"token": "",
"x": 1280,
"y": 400,
"wires": []
},
{
"id": "83c04ba9.69b57",
"type": "inject",
"z": "e50cb0c0.87ac9",
"name": "Each hours between 10h and 00h",
"topic": "",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "0 10-23 * * *",
"once": false,
"onceDelay": 0.1,
"x": 200,
"y": 240,
"wires": [
[
"90a28e1d.c93698"
]
]
},
{
"id": "90a28e1d.c93698",
"type": "http request",
"z": "e50cb0c0.87ac9",
"name": "Retrieve HTTP ical",
"method": "GET",
"ret": "txt",
"paytoqs": false,
"url": "",
"tls": "",
"proxy": "",
"x": 490,
"y": 240,
"wires": [
[
"1a2c9ae8.e9d5b5"
]
]
},
{
"id": "1a2c9ae8.e9d5b5",
"type": "function",
"z": "e50cb0c0.87ac9",
"name": "Convert into a readable format and copy it inside flow.new_calendrier ",
"func": "// Retrieve description\ndescription_raw = msg.payload.split(\"SUMMARY:\");\nvar description = [];\ndescription_raw.forEach(function (item, index) {\n if(index !== 0){\n description.push(item.split(\"\\n\")[0].trim());\n }\n});\n\n// Retrieve date\ndate_raw = msg.payload.split(\"DTSTART;\");\nvar message = \"Here is the list of worshops:\\n------------------------\\n\";\n\ndate_raw.forEach(function (item, index) {\n if(index !== 0){\n\n icalStr = item.split(\"\\n\")[0].trim();\n icalStr = item.split(\":\")[1].trim();\n\n //Convert time\n var strYear = icalStr.substr(0,4);\n var strMonth = icalStr.substr(4,2);\n var strDay = icalStr.substr(6,2);\n \n //Convert date to days\n strDate = strMonth + \"/\" + strDay + \"/\" + strYear;\n var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\n strDayFull = days[new Date(strDate).getDay()];\n\n //Convert date to month\n var month = ['January', 'February', 'March', 'April', 'May', 'Juin', 'July', 'August', 'September', 'October', 'November', 'December'];\n strMonthFull = month[new Date(strDate).getMonth()]; \n message += description[index-1] + \" --> \" + strDayFull + \" \" + strDay + \" \" + strMonthFull + \"\\n\";\n }\n});\n\n//End message\nmessage += \"\\n More info on [ADDRESS]\";\n\n//Copy message to new_calendrier variable\nflow.set(\"new_calendar\", message);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 930,
"y": 240,
"wires": [
[
"56a42c0a.67eca4"
]
]
},
{
"id": "bae2b4d5.2d0e58",
"type": "switch",
"z": "e50cb0c0.87ac9",
"name": "Compare distant ICAL <--> Local ICAL ?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "neq",
"v": "new_calendar",
"vt": "flow"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 600,
"y": 380,
"wires": [
[
"1328f9ed.07ba7e"
]
]
},
{
"id": "1e2b2d02.a824ab",
"type": "file",
"z": "e50cb0c0.87ac9",
"name": "Write calendar.xml",
"filename": "/home/pi/calendar.xml",
"appendNewline": true,
"createDir": false,
"overwriteFile": "true",
"x": 1290,
"y": 340,
"wires": [
[]
]
},
{
"id": "ae937e21.53e7f",
"type": "file in",
"z": "e50cb0c0.87ac9",
"name": "Read calendar.xml",
"filename": "/home/pi/calendar.xml",
"format": "utf8",
"chunk": false,
"sendError": false,
"x": 150,
"y": 380,
"wires": [
[
"751939ce.a9c138"
]
]
},
{
"id": "1328f9ed.07ba7e",
"type": "change",
"z": "e50cb0c0.87ac9",
"name": "Change payload to new version",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "new_calendrier",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 950,
"y": 380,
"wires": [
[
"1e2b2d02.a824ab",
"64569321.c6707c"
]
]
},
{
"id": "751939ce.a9c138",
"type": "function",
"z": "e50cb0c0.87ac9",
"name": "Bug",
"func": "msg.payload = msg.payload.substring(0, msg.payload.length - 1);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 370,
"y": 380,
"wires": [
[
"bae2b4d5.2d0e58"
]
]
},
{
"id": "56a42c0a.67eca4",
"type": "fs-ops-access",
"z": "e50cb0c0.87ac9",
"name": "Calendar.xml exists ?",
"path": "/home/pi/",
"pathType": "str",
"filename": "calendar.xml",
"filenameType": "str",
"read": true,
"write": true,
"throwerror": false,
"x": 310,
"y": 300,
"wires": [
[
"ae937e21.53e7f"
],
[
"65b65ab2.22b9fc"
]
]
},
{
"id": "bf683c1d.d1e7b",
"type": "file",
"z": "e50cb0c0.87ac9",
"name": "Create calendar.xml",
"filename": "/home/pi/calendar.xml",
"appendNewline": true,
"createDir": false,
"overwriteFile": "true",
"x": 880,
"y": 300,
"wires": [
[
"ae937e21.53e7f"
]
]
},
{
"id": "65b65ab2.22b9fc",
"type": "change",
"z": "e50cb0c0.87ac9",
"name": "Change to empty",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 590,
"y": 300,
"wires": [
[
"bf683c1d.d1e7b"
]
]
},
{
"id": "b6039bd1.38b3c8",
"type": "fs-ops-delete",
"z": "e50cb0c0.87ac9",
"name": "",
"path": "/home/pi",
"pathType": "str",
"filename": "calendar.xml",
"filenameType": "str",
"x": 330,
"y": 500,
"wires": [
[]
]
},
{
"id": "6951a561.82df14",
"type": "inject",
"z": "e50cb0c0.87ac9",
"name": "Reset Calendar",
"topic": "",
"payload": "",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 500,
"wires": [
[
"b6039bd1.38b3c8"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment