Created
January 11, 2017 13:08
-
-
Save z0mt3c/56e215b2828cb507d6e5dc1d51df8c17 to your computer and use it in GitHub Desktop.
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
const superagent = require('superagent') | |
var agent = superagent.agent() | |
var pattern = /<tr>\s*<td>\s*([^<]+)<span[^>]+>([^<]*)<\/span>\s*<\/td>\s*<td>\s*<span class="AutoUpdateValue ID([0-9]*)[^>]+>([^<]*)<\/span>\s*<\/td>\s*<\/tr>/g | |
var fetch = module.exports = function (user, password, systemId) { | |
return new Promise((resolve, reject) => { | |
agent | |
.post('https://www.nibeuplink.com/LogIn') | |
.send(`Email=${user}`) | |
.send(`Password=${password}`) | |
// .redirects(2) // not necessary? | |
.then(function () { | |
agent | |
.get(`https://www.nibeuplink.com/System/${systemId}/Status/ServiceInfo`) | |
.then(function (res) { | |
var match | |
var results = [] | |
while ((match = pattern.exec(res.text))) { | |
var entry = match.slice(1, 5).map(i => i.trim()) | |
results.push({ | |
id: entry[2], | |
title: entry[0], | |
variableDesignation: entry[1] === '' ? null : entry[1], | |
value: entry[3] === '--' ? null : entry[3] | |
}) | |
} | |
resolve(results) | |
}) | |
}) | |
}) | |
} | |
fetch('user', 'passwort', 123).then((results) => console.log(results)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment