From 57a35dec7559ffcba0d10f0200c606fde7f56df5 Mon Sep 17 00:00:00 2001 From: Cedric Hoelzl Date: Sun, 21 Jul 2019 11:31:49 +0200 Subject: [PATCH] Init --- main.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 main.js diff --git a/main.js b/main.js new file mode 100644 index 0000000..51ab82e --- /dev/null +++ b/main.js @@ -0,0 +1,60 @@ + +const request = require('request'); +const parse5 = require('parse5'); + +const url = 'https://polylan.ch'; +const groupid = -14795224; + +let old1 = 1179 +let old2 = 486 +function cb(ret,err){ + request(url, function (error, response, body) { + try{ + const doc = parse5.parse(body).childNodes[1].childNodes[2].childNodes[34].childNodes[1].childNodes[1].childNodes[1].childNodes[5]; + const d1 = doc.childNodes[1].childNodes[3].childNodes[3].childNodes[4].value; + const d2 = doc.childNodes[3].childNodes[3].childNodes[3].childNodes[4].value; + + const dif1 = d1 - old1; + const dif2 = d2 - old2; + old1 = d1 + old2 = d2 + + ret([dif2,dif1]); + }catch(e){ + err( e); + } + }); +} + +function handle_message (event, bot){ + if(event.update.message.text){ + var txt = event.update.message.text; + return; + } +} + + +module.exports = function(){ + + this.cron = function(cron,bot){ + this.bot = bot; + this.cronb = function(that){ + new cron('59 34 0,6,12,18 * * *', function(){ + cb((res)=>{ + return that.bot.telegram.sendMessage(groupid,"Mieux que 0 !",{}); + },(err)=>{ + bot.log.error(err) + return; + }) + }, null, true, 'Europe/Zurich'); + } + } + this.handle = function(event, bot){ + if(event.update.message){ + return handle_message(event, bot); + } + return; + } + + this.name = "PolyCB"; +}