@pinsdorf
I am moving forward and getting closer to my target.
With your tips i got rid of the Express framework (calling http://localhost/scrape to start web scraping). I also found a way two show the results in the console and addition writing a file (for my personal debugging).
Right now i have to files:
package.json
{
"name" : "MMM-Alex2",
"version" : "0.0.1",
"description" : "Reverse Lookup Phonenumber.",
"main" : "server.js",
"author" : "Alex",
"repository" : {
"type" : "git",
"url" : "https://github.com/"
},
"dependencies" : {
"request" : "latest",
"cheerio" : "latest"
}
}
server.js
var request = require('request');
var cheerio = require('cheerio');
var moment = require('moment');
var fs = require('fs');
var callnr = '0049xxxx';
var url = 'http://www.dasoertliche.de/?form_name=search_inv&ph=' + callnr;
title = '';
adresse = '';
anrufer = 'kein Treffer auf Örtliche.de für '+ callnr;
request(url, function (error, response, html) {
if (!error) {
var $ = cheerio.load(html);
$('.left').filter(function(){
var data = $(this);
title = data.text().trim();
//adresse = data.children().children().text().trim();
adresse = data.children().eq(2).text().trim();
})
$('.name ').filter(function(){
var data = $(this);
anrufer = data.text().trim();
})
console.log('Anrufer: ' + anrufer);
console.log('Adresse: ' + adresse);
//console.log('Title: ' + title);
console.log('Gesamt: ' + anrufer + ', ' + adresse + ' - '+ moment().format("DD.MM.YYYY HH:mm"));
//Daten fortschreiben
fs.appendFile('anrufe.txt', moment().format("DD.MM.YYYY HH:mm") + ' Gesamt: ' + anrufer + ', ' + adresse +'\n', function(err){
console.log('File successfully written!');
})
}
else {
console.log("We’ve encountered an error: " + error);
}
});
If i put them in a folder (under MagicMirror/modules
) an do a npm install
in that folder, it will install the depencies.
If in now run node server.js
in MagicMirror/modules/FOLDERNAME
i will get the result of a static phonenumber in the console and in a textfile in FOLDERNAME
.
My next step will be the implementation in MMM-Fritz-Box-Callmonitor, as you suggested.
AxLED