@lolo there it is.
many, many, many thanks. and thanks for adding explanations
Read the statement by Michael Teeuw here.
Posts made by Amoniak
-
RE: module that displays a certain text from a website, the text on the website is updated daily
-
RE: module that displays a certain text from a website, the text on the website is updated daily
@lolo
thank you, I’ll try right now -
RE: module that displays a certain text from a website, the text on the website is updated daily
@lolo
i did that. it is still not displayed
i added this configuration in the config.js file:{
module: “MMM-Dnevni_citat”,
position: “middle_center” -
RE: module that displays a certain text from a website, the text on the website is updated daily
@lolo thank you for the code.
I used the “MagicMirror-Module-Template” to create a new file and the associated folder.
this is my js:‘’’
Module.register(“dnevni_citat”, {
defaults: {
updateInterval: 60000,
retryDelay: 5000
},requiresVersion: "2.1.0", // Required version of MagicMirror start: function() { var self = this; var dataRequest = null; var dataNotification = null; //Flag for check if module is loaded this.loaded = false; // Schedule update timer. this.getData(); setInterval(function() { self.updateDom(); }, this.config.updateInterval); }, const url= 'https://wol.jw.org/hr/wol/h/r19/lp-c'; request({ url: url, method: 'GET' }, (error, response, body) => { if (error) { return console.error(error) }; var $ = cheerio.load(body); //console.log($.html()); const data = $('div[class="tabContent"]').first(); let header = $(data).find('h2').text(); let title = $(data).find('p').first().text(); let text = $(data).find('div.pGroup>p').text(); //console.log(header,title,text); var recivedData={ header, title, text }; //console.log(recivedData); } },
‘’’
what am I doing wrong? -
RE: module that displays a certain text from a website, the text on the website is updated daily
so, this is what my NodeHelper.js looks like. like i thought, the screen is black.
const axios = require("axios"); const DetectLanguage = require("detectlanguage"); module.exports = NodeHelper.create({ socketNotificationReceived: async function(noti, payload) { if (noti === "START") { if (payload.updateInterval < 120000) { payload.updateInterval = 120000; } const self = this; (async function displayWatchtower () { const poem = await getWatchtower(payload); self.sendSocketNotification("UPDATE", poem); setTimeout(displayPoem, payload.updateInterval); })(); } } }); const cheerio = require("cheerio"); const axios = require("axios").default; const fethHtml = async url => { try { const { data } = await axios.get(url); return data; } catch { console.error(`ERROR: An error occurred while trying to fetch the URL: ${url}`); } }; const extracWatchtower = selector => { const theme = selector .find(".tabContent active") .find("[class='themeScrp'] > [class='b']) .text() .trim(); const text = selector .find(".bodyTxt") .find("[class='section']") .text() .trim(); return { theme, text }; }; const scrapWatchtower = async () => { const watchtowerUrl = "https://wol.jw.org/hr/wol/h/r19/lp-c"; const html = await fethHtml(watchtowerUrl); const selector = cheerio.load(html); const searchResults = selector("body") .find("#dailyText" ); const deals = searchResults.map((idx, el) => { const elementSelector = selector(el); return extractDeal(elementSelector) }) .get(); return Watchtower; };
-
RE: module that displays a certain text from a website, the text on the website is updated daily
i installed cheerio, but i don’t know how to use it.
do I have to put this now in my “MMM-PoemOfTheDay.js” ?
-
RE: module that displays a certain text from a website, the text on the website is updated daily
well, I’ll get started then. Keep your fingers crossed.
-
RE: module that displays a certain text from a website, the text on the website is updated daily
@ashishtank i got it now, i will now try to parse the html response to extract the text, any good tips?
-
RE: module that displays a certain text from a website, the text on the website is updated daily
@ashishtank ok, I have installed the module, but it only shows me a black screen
-
RE: module that displays a certain text from a website, the text on the website is updated daily
@ashishtank said in module that displays a certain text from a website, the text on the website is updated daily:
MMM-PoemOfTheDay is perfect to adapt for your need. Instead of poem site you need to get data from WatchTower site and parse the html response to extract the text.
wow, thank you very much for your feedback, I’ll try to see if I can do it.