• 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.

Help with puppeteer ,cheerio and json

Scheduled Pinned Locked Moved Development
9 Posts 2 Posters 746 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.
  • S Offline
    sdetweil @lolo
    last edited by Dec 8, 2020, 6:50 PM

    @lolo ignore the class= for the moment. that will just make it look prettier w colors etc

    A table is a list of rows. Which contain a list of columns
    A table is table
    A row is tr
    A column is td

    Your data is an array []
    Of objects{}

    You can use the for loop to process you data
    This is pseudo code, I am on my phone
    for(let item of array_name){
    Create row.
    Create td = item.element_name
    Etc
    }

    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 Dec 8, 2020, 7:42 PM

      Thanks for replay.
      I believe, I dint explained well.
      This is table from website. Screenshot.
      table.jpg
      The data what i menage to collect is from prev sibling of tr class tableRow.
      What i wish to get is tr class datum as first date and then data of street, street number, time (all in span) as data object in array, till next tr datum and then same after.
      For each span id is different but they sharing same part of one number in id.
      I cant use for for each as element (td or tr) as plenty of them are useless.
      And here I’m stuck. I tried different approaches but then all data was multiplying or got empty object in arrays
      example from website
      date.PNG
      Capture.PNG

      S 1 Reply Last reply Dec 8, 2020, 8:15 PM Reply Quote 0
      • S Offline
        sdetweil @lolo
        last edited by Dec 8, 2020, 8:15 PM

        @lolo but u have the date already in the object. Sort them maybe, but cheerio should return the list in order.

        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 Dec 8, 2020, 8:28 PM

          Yes I’m getting date , but this one is endWork (kraj). When the interruption will end, not to start. I know maybe I should use that.

          1 Reply Last reply Reply Quote 0
          • L Offline
            lolo
            last edited by Dec 9, 2020, 11:47 AM

            I think i managed to sort it out.

            	const $ = cheerio.load(html);
                
            	var water = [];
                    var waterList = [];
                    var el = $('#cphContent_cphSadrzaj_upVoda table tbody ');
                
            	if (el) {
                           var elementWater = $('#cphContent_cphSadrzaj_upVoda table tbody  span').filter(function () {
                              return $(this).text() === self.place;
                               }).parent().parent();
                         $(elementWater).each(function (jex, edate) {
            
                        const $edate = $(edate);
                        var startDate = $edate.prev().find('tr[class="datum"]>th>div').text().trim();
                        var street = $edate.find('span[id*="Label2"]').text();
                        var streetNmbr = $edate.find('span[id*="Label7"]').text();
                        var startTime = $edate.find('span[id*="Label8"]').text();
                        var endTime = $edate.find('span[id*="Label9"]').text();
                        var endWork = $edate.find('span[id*="Label10"]').text();
            
                        var water = {
                            startDate,
                            street,
                            streetNmbr,
                            startTime,
                            endTime,
                            endWork
                        };
                        
                    
                        waterList.push(water);
                        console.log(water);
                    });
            
                };
                if (!el) {
                    console.log('No new entries!');
                };
                var waterWork = JSON.parse(JSON.stringify(waterList));
                self.sendSocketNotification('ELECTRIC_POWER_DISCONNECTED', waterWork);
            

            Now i can get all data sorted by config.place

             {
              startDate: '09.12.2020',
              street: 'ISTARSKA, Rijeka',
              streetNmbr: '64',
              startTime: '10:00',
              endTime: '14:00',
              endWork: '09.12.20'
            }
            
            
            S 1 Reply Last reply Dec 9, 2020, 12:42 PM Reply Quote 0
            • S Offline
              sdetweil @lolo
              last edited by Dec 9, 2020, 12:42 PM

              @lolo cool

              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 Dec 14, 2020, 7:01 PM

                This is output of my module. Any suggestion about styling.
                srdoči.PNG
                šmrika.PNG
                brnelići.PNG
                croatian
                brnelići2.PNG

                I know there are more things to make it better but i have to learn it first.

                S 1 Reply Last reply Dec 14, 2020, 9:28 PM Reply Quote 0
                • S Offline
                  sdetweil @lolo
                  last edited by Dec 14, 2020, 9:28 PM

                  @lolo i cannot help with look. Totally useless here

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    6/9
                    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