• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

module that displays a certain text from a website, the text on the website is updated daily

Scheduled Pinned Locked Moved Requests
36 Posts 6 Posters 7.7k Views 7 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.
  • A Offline
    ashishtank Module Developer @Amoniak
    last edited by Jan 20, 2021, 4:07 PM

    @Amoniak any error in dev console or PM2/terminal ?

    A 1 Reply Last reply Jan 20, 2021, 5:15 PM Reply Quote 0
    • A Offline
      Amoniak @ashishtank
      last edited by Jan 20, 2021, 5:15 PM

      @ashishtank i got it now, i will now try to parse the html response to extract the text, any good tips?

      A E 2 Replies Last reply Jan 20, 2021, 5:36 PM Reply Quote 0
      • A Offline
        ashishtank Module Developer @Amoniak
        last edited by Jan 20, 2021, 5:36 PM

        @Amoniak yes, I checked the response from watch tower in postman and they give data of last 2-3 days or may be from Sunday to this day, so you will need to select the right node. You can use class tabContent as identifier and today’s date for selection of the node. Also check which html parse is good enough, as HTML is very complex to parse you may want to choose right parser which gives speed and is lightweight. i.e. node-html-parser

        2021-01-20-18-33-58-Clipboard

        Other thing you can do is once you have parsed text data from watch tower, you can assign it to poem’s format (title, content and name) and it will just work. later on you can change the UI and text property names if you want.

        S 1 Reply Last reply Jan 20, 2021, 6:07 PM Reply Quote 0
        • S Away
          sdetweil @ashishtank
          last edited by sdetweil Jan 20, 2021, 6:07 PM Jan 20, 2021, 6:07 PM

          @ashishtank cheerio lib will parse html to json

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 1
          • A Offline
            Amoniak
            last edited by Jan 20, 2021, 7:56 PM

            well, I’ll get started then. Keep your fingers crossed.

            1 Reply Last reply Reply Quote 0
            • A Offline
              Amoniak
              last edited by Amoniak Jan 20, 2021, 10:34 PM Jan 20, 2021, 10:11 PM

              i installed cheerio, but i don’t know how to use it.
              do I have to put this now in my “MMM-PoemOfTheDay.js” ?
              Bild 20.01.21 um 23.10.jpg

              S 1 Reply Last reply Jan 20, 2021, 10:19 PM Reply Quote 0
              • S Away
                sdetweil @Amoniak
                last edited by Jan 20, 2021, 10:19 PM

                @Amoniak gotta go read the library usage

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • L Offline
                  lolo
                  last edited by Jan 20, 2021, 11:01 PM

                  It gonna be harder than u think as your text is changing daily. Just follow the the pattern.
                  Every day this is changed( https://wol.jw.org/hr/wol/h/r19/lp-c).
                  new day new text.
                  Text is in :
                  div id=“dailyText”
                  but if you ignore reference in text as (Mat. 16:24, 25; Ivan 15:20) located in a class it’s gonna be more easier.
                  And with cheerio u can complete this.

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    Amoniak
                    last edited by Jan 21, 2021, 4:12 PM

                    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;
                    
                    };
                    
                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      ashishtank Module Developer
                      last edited by Jan 21, 2021, 4:35 PM

                      @Amoniak there are lots of missing pieces… add console.log with some message in each function and see how the flow works.

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 2 / 4
                      2 / 4
                      • First post
                        19/36
                        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