MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Custom module bases helloworld

    Scheduled Pinned Locked Moved Development
    2 Posts 2 Posters 1.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      roma-cezar
      last edited by roma-cezar

      Hi everyone! Now i started to use magicMirror and want to build my simple custom module to indncate somrthing (traffic load at now).
      I wrote a scrypt

      var text1 = "";
      var text2 = "";
      var text3 = "";
      var htmlpage = 'https://www.yandex.ru';
      
      var request = require('request');
      var DomParser = require('dom-parser');
      var parser = new DomParser();
      var dom;
      setInterval(function() {
      request(htmlpage, function(error, response, body) {
      dom = parser.parseFromString(body);
      text1 = dom.getElementsByClassName('traffic i-bem')[0].innerHTML;
      
      dom = parser.parseFromString(text1);
      text2 = dom.getElementsByTagName('H1')[0].innerHTML;
      dom = parser.parseFromString(text2);
      text3 = dom.getElementsByClassName('link link_black_yes')[0].textContent });
      }, 1000);
      

      request and dom-parser eas intalled.
      Then i get text data string and i want to set it into the Hello world module next.

      I added my scrypt code into the module code here:

      getDom: function() {
         var wrapper = document.createElement("div");
         wrapper.innerHTML = this.config.text;
         return wrapper;
      }
      

      But it doesnt work (request and parser modules). Otherwise, just counting number works well(((.

      Could not you help me, what i have to do to get my scrypt working inside helloworld module?

      strawberry 3.141S 1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @roma-cezar
        last edited by

        @roma-cezar you need to put your code into a node_helper as it is based on node dependencies. Then you can communicate via sockets between the helper and the module. you can have a look in other modules which have a node_helper file how the communication works. also you can have a look in the developer guide here https://github.com/MichMich/MagicMirror/blob/master/modules/README.md

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Enjoying MagicMirror? Please consider a donation!
        MagicMirror created by Michael Teeuw.
        Forum managed by Sam, technical setup by Karsten.
        This forum is using NodeBB as its core | Contributors
        Contact | Privacy Policy