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

    Chiiki58

    @Chiiki58

    0
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Chiiki58 Unfollow Follow

    Latest posts made by Chiiki58

    • RE: Error Node_helper custome Module

      It works, thank you very much for the input. I’ll probably upload it to GIT once I get the layout right. Now I’ve just unstructured all the text from the website

      posted in Development
      C
      Chiiki58
    • RE: Error Node_helper custome Module

      @sdetweil Yeah of course I have everything in the right folder with the right name

      I also had cheerio installed, I’ll have to check it out

      I’ll try it with httptojson

      Thank you very much, Sam

      posted in Development
      C
      Chiiki58
    • Error Node_helper custome Module

      Hey Guys i’m trying to set up a custome Module to screen the menu of my scools canteen. I ask ChatGPT for the Scripts but he can’t help me anymore thats the reason why i write here.

      The module is called MenuZFV and has a .js file as well as .css and also a node_helper.js which I paste below. The problem is the data can be accessed from the website: (‘https://app.food2050.ch/de/stfw/restaurant -stfw/menu/mittagsmenue/weekly?week=26’) cannot be accessed. Npm install in the folder was done. ChatGPT recommended puppeteer to me because there is no DOM on the website, I installed it via npm install, but when I run node node_helper.js this log comes up - can anyone help me?

      LOG:

      node:internal/modules/cjs/loader:1051
        throw err;
        ^
      
      Error: Cannot find module 'node_helper'
      Require stack:
      - /home/pi/MagicMirror/modules/MMM-MenuZFV/node_helper.js
          at Module._resolveFilename (node:internal/modules/cjs/loader:1048:15)
          at Module._load (node:internal/modules/cjs/loader:901:27)
          at Module.require (node:internal/modules/cjs/loader:1115:19)
          at require (node:internal/modules/helpers:130:18)
          at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-MenuZFV/node_helper.js:1:20)
          at Module._compile (node:internal/modules/cjs/loader:1241:14)
          at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
          at Module.load (node:internal/modules/cjs/loader:1091:32)
          at Module._load (node:internal/modules/cjs/loader:938:12)
          at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12) {
        code: 'MODULE_NOT_FOUND',
        requireStack: [ '/home/pi/MagicMirror/modules/MMM-MenuZFV/node_helper.js' ]
      }
      

      Node.js v20.8.0

      .JS:

      const puppeteer = require('puppeteer');
      
      (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        const url = 'https://app.food2050.ch/de/stfw/restaurant-stfw/menu/mittagsmenue/weekly?week=26';
      
        try {
          await page.goto(url, { waitUntil: 'networkidle2' });
      
          const menuItems = await page.evaluate(() => {
            const items = [];
            document.querySelectorAll('p.sc-e418db57-3.eOyIUO').forEach(item => {
              items.push(item.textContent.trim());
            });
            return items;
          });
      
          console.log('Menu Items:');
          console.log(menuItems);
      
        } catch (error) {
          console.error('Error fetching menu:', error);
        } finally {
          await browser.close();
        }
      })();
      

      .CSS:

      .MMM-MenuZFV .day {
          font-weight: bold;
          padding-top: 10px;
      }
      
      .MMM-MenuZFV .menu-name {
          text-align: left;
      }
      
      .MMM-MenuZFV .menu-price {
          text-align: right;
      }
      

      NODE_HELPER.JS:

      const NodeHelper = require('node_helper');
      const puppeteer = require('puppeteer');
      
      module.exports = NodeHelper.create({
        start: function () {
          console.log('Starting node helper for: ' + this.name);
        },
      
        socketNotificationReceived: function (notification, payload) {
          if (notification === 'GET_MENU') {
            console.log('Fetching menu from URL: ' + payload.url); // Log the URL being fetched
            this.getMenu(payload.url); // Pass the URL from payload
          }
        },
      
        getMenu: async function (url) {
          try {
            const browser = await puppeteer.launch({ headless: true });
            const page = await browser.newPage();
            await page.goto(url, { waitUntil: 'networkidle2' });
      
            const menuItems = await page.evaluate(() => {
              const items = [];
              document.querySelectorAll('p.sc-e418db57-3.eOyIUO').forEach(item => {
                items.push(item.textContent.trim());
              });
              return items;
            });
      
            await browser.close();
      
            console.log('Extracted menu items:');
            console.log(menuItems);
      
            if (menuItems.length === 0) {
              menuItems.push('Kein Menü gefunden.');
            }
      
            this.sendSocketNotification('MENU_RESULT', menuItems);
          } catch (error) {
            console.error('Error fetching menu:', error);
            this.sendSocketNotification('MENU_RESULT', ['Fehler beim Abrufen des Menüs.']);
          }
        }
      });
      

      Thank you very much for your time and help.

      posted in Development
      C
      Chiiki58