MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. lolo
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    L
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 29
    • Groups 0

    lolo

    @lolo

    -2
    Reputation
    95
    Profile views
    29
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    lolo Unfollow Follow

    Best posts made by lolo

    • MMM-HNB-Exchange

      It uses API from HNB (Croatian National Bank) to pull currency exchange rate data for croatian kuna.

      Screenshot

      mode: “carousel” - rotate between currency
      Capture.PNG

      mode: “table”
      Capture2.PNG

      Download
      MMM-HNB-Exchange

      Configuration:

      {
          module: "MMM-HNB'Exchange",
          position: "top_right",
          config: {
              decimal: 2, 
              currency: ['GBP', 'USD', 'EUR', 'BAM', 'AUD', 'CAD'],
              mode: "table", //"carousel"  or  "table"
          }
      },          
      

      Version:
      28.12.2020 - v1.0.0 - Initial Release

      posted in Productivity
      L
      lolo
    • MMM-Fuel-HR fuel prices from various gas station in Croatia

      I am very happy to announce one of the first module. Others are still in the alpha version and this one is in beta.

      Description:
      It is scraping for fuel prices, location and distance of various gas stations in Croatia. The result is returned as the lowest price in the radius of the selected location.
      It is limited to show up to five OPEN stations in range of radius.

      Screenshots:
      Capture.PNG
      Download
      MMM-Fuel-HR

      Version
      23.12.2020 - v1.0.0 - Initial Release Beta

      Any feedback from anyone is more than welcome.

      posted in Transport
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      This should be your node_helper.

      const NodeHelper = require("node_helper");
      const cheerio = require("cheerio");
      const request = require('request');
      
      module.exports = NodeHelper.create({
      
          start: function () {
              self = this;
              console.log("Starting node_helper for: " + this.name);
          },
      
          getData: function () {
              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);
                  
      			self.sendSocketNotification('TEXT_RESULT', recivedData);
              });
          },
      
          socketNotificationReceived: function (notification, payload) {
      
              if (notification === 'GET_TEXT_DATA') {
                  self.getData();
              }
          },
      });
      
      
      posted in Requests
      L
      lolo

    Latest posts made by lolo

    • MMM-Animation-MM

      MagicMirror text animation demo.
      Animating SVG with CSS.
      Capture.PNG

      MMM-Animation-MM

      Idea is build complete module, start animation once on startup and when the monitor turn on, but all other modules must be suspended till the animation end .
      I will appreciate any thoughts about how to achieve this.

      posted in Fun & Games
      L
      lolo
    • RE: MMM-Toon: ReferenceError: NodeHelper is not defined

      @Nymeia You’re Welcome.

      posted in Troubleshooting
      L
      lolo
    • RE: MMM-Toon: ReferenceError: NodeHelper is not defined

      @Nymeia Try to add this on beginning of node_helper

      const NodeHelper = require('node_helper');
      
      posted in Troubleshooting
      L
      lolo
    • RE: Boot Magic Mirror on start up.

      @Santanachia I have never tried. MagicMirrorOS

      posted in Troubleshooting
      L
      lolo
    • RE: 0First Time setup. Will not launch with 2 added modules

      @avsfanwilly15 in module: “newsfeed”, missing bracket } .

      Please correct syntax errors at or above this line: /home/pi/MagicMirror/config/config.js:103
      		{
      

      You should hide appid: and private calendar urls: from config.js when uploading to forum

      posted in Troubleshooting
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      @Amoniak you’re welcome.
      Just delete the second appendChild in MMM-Dnevni_citat.js

                  var table = document.createElement('tr');
                  table.classList.add("xsmall", "normal");
                  var title = document.createElement('tr');
                  title.innerHTML = this.textDataRecived.title;
                  table.appendChild(title);
                  var textData = document.createElement('tr');
                  textData.innerHTML = this.textDataRecived.textData;
      
                  table.appendChild(textData);
                  table.appendChild(title);        // delete this one
                  wrapper.appendChild(table);
      
      

      I added twice,my mistake.

      posted in Requests
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      @Amoniak
      This should fix the problem with loading text for current Date.
      node_helper:

      const NodeHelper = require("node_helper");
      const cheerio = require("cheerio");
      const request = require('request');
      var self;
      const ur = 'https://wol.jw.org/wol/dt/r19/lp-c';
      
      module.exports = NodeHelper.create({
      
          start: function () {
              self = this;
              self.browser
              console.log("Starting node_helper for: " + this.name);
          },
      
          getData: function () {
              var self = this;
              var url = self.setURL();
              request({
                  url: url,
                  method: 'GET'
              }, (error, response, body) => {
                  if (!error) { 
                      var result = JSON.parse(body);
                      var contentData = result.items[0].content;
                      var $ = cheerio.load(contentData);
                      //console.log("cheerio:  ", $.html());
                      var header = $('html>body>header>h2').text();
                      var title = $('p').first().text();
                      var textData = $('p').first().next().text().replace(/(\r\n|\n|\r)/gm, "");
                      var recivedData = {
                          header,
                          title,
                          textData
                      };
                      //console.log(recivedData);    
      				self.sendSocketNotification('TEXT_RESULT', recivedData);
                  }
                  if (error) { 
                      console.log(error);
                  }
              });
      
          },
      
          setURL: function () {
              console.log("ur old: ", ur);
              var utc = new Date().toJSON().slice(0, 10).replace(/-/g, '/');
              var newURL = ur.concat("/").concat(utc);
              return newURL
          },
      
      
          socketNotificationReceived: function (notification, payload) {
              var self = this;
              if (notification === 'GET_TEXT_DATA') {
                  self.getData();
              }
          },
      });
      
      posted in Requests
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      node_helper. But need to find different approach.

      const NodeHelper = require("node_helper");
      const cheerio = require("cheerio");
      const request = require('request');
      var self;
      module.exports = NodeHelper.create({
      
          start: function () {
              self = this;
              console.log("Starting node_helper for: " + this.name);
          },
      
          getData: function () {
              
      		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: ",error)
                  }
                  if (!error && response.statusCode == 200) {
                  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 textData = $(data).find('div.pGroup>p').text();
                  //console.log(header,title,text);
                  var recivedData = {
                      header,
                      title,
                      textData
                  }
      			//console.log('recivedData: ',recivedData);
                  
      			self.sendSocketNotification('TEXT_RESULT', recivedData);
      			}
              });
          },
      
          socketNotificationReceived: function (notification, payload) {
           var self = this;
              if (notification === 'GET_TEXT_DATA') {
                  //console.log(notification,payload);
      			self.getData();
              }
          },
      });
      
      

      MMM-Dnevni_citat.js. getDom need some styling.

      Module.register("MMM-Dnevni_citat", {
          defaults: {
              updateInterval: 10 * 60 * 1000, //  minute ,seconds ,milliseconds
              //retryDelay: 5000          // not needed for now
          },
          start: function () {
              Log.info("Starting module: " + this.name);
              requiresVersion: "2.1.0";
              this.loaded = false;
              this.scheduleUpdate();
      
          },
          scheduleUpdate: function () {
              setInterval(() => {
                  this.getData();
              }, this.config.updateInterval);
              this.getData();
          },
          getData: function () {
              console.log(' GET_TEXT_DATA ', this.config)
              this.sendSocketNotification('GET_TEXT_DATA', this.config);
          },
          socketNotificationReceived: function (notification, payload) {
              if (notification === "TEXT_RESULT") {
                  this.textDataRecived = payload;
                  console.log(this.textDataRecived);
                  this.loaded = true;
              }
              this.updateDom();
      
          },
      
          getDom: function () {
              var wrapper = document.createElement("div");
      
              if (!this.loaded) {
                  wrapper.innerHTML = "LOADING";
                  return wrapper;
              }
              if (this.loaded) {
                  var header = document.createElement("header");
                  header.innerHTML = this.textDataRecived.header;
                  wrapper.appendChild(header);
      
                  var table = document.createElement('tr');
                  table.classList.add("xsmall", "normal");
                  var title = document.createElement('tr');
                  title.innerHTML = this.textDataRecived.title;
                  table.appendChild(title);
                  var textData = document.createElement('tr');
                  textData.innerHTML = this.textDataRecived.textData;
      
                  table.appendChild(textData);
                  table.appendChild(title);
                  wrapper.appendChild(table);
      
              }
              return wrapper;
          },
      });
      
      

      config.js

      		{    module: "MMM-Dnevni_citat",
                   position: "middle_center"
      		 },
      
      posted in Requests
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      It’s not displayed as DOM elements are not created.
      But there is another problem with cheerio, is not loading any data for Saturday and Sunday. This is because of website. Need to find another approach.

      posted in Requests
      L
      lolo
    • RE: module that displays a certain text from a website, the text on the website is updated daily

      Now create MMM-Dnevni_citat.js
      Inside you need first to registar module

      Module.register("MMM-Dnevni_citat", {
      	defaults: {
      		updateInterval:  10 x  60 x 1000,       //  minute ,seconds ,milliseconds
      		//retryDelay: 5000          // not needed for now
      	},
      

      Then first function will be start function

         start: function () {
              Log.info("Starting module: " + this.name);
              requiresVersion: "2.1.0";
              this.loaded = false;
              this.scheduleUpdate();
      
          },
      

      with first function we are calling second ( scheduleUpdate) , how often will fetch data.

         scheduleUpdate: function () {
              setInterval(() => {
                  this.getData();
              }, this.config.updateInterval);
              this.getData();
          },
      

      Then we are calling getData function. Sending socketNotification to node_helper.

      getData: function () {
              this.sendSocketNotification(''GET_TEXT_DATA'', this.config);
          },
      

      Whe node_helper send back, next function will check if data is received and update DOM

      socketNotificationReceived: function (notification, payload) {
             if (notification === "TEXT_RESULT") {
                 this.textDataRecived = payload;
                 this.loaded = true;
            },this.updateDom();
      

      Now only is left to create DOM

          getDom: function () {
              var wrapper = document.createElement("div");
      
              if (!this.loaded) {
                  wrapper.innerHTML = "LOADING";
                  return wrapper;
              }
              if (this.loaded) {
             // here to add elements and styling
                 return wrapper;
             }
          },
      
      posted in Requests
      L
      lolo