Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    MMM-MealViewer

    Development
    6
    48
    4053
    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.
    • G
      gonzonia @cowboysdude last edited by gonzonia

      @cowboysdude Thanks! I might switch to that. I’ve had to rework it a little because the URL wasn’t getting set except at the first call. I just moved setup for that into the getMenuData and I think it’s all working now. I’ll give it a day to run and see what happens tomorrow before I try messing with it again and update the file on github.

      -updated to fix grammar

      1 Reply Last reply Reply Quote 1
      • cowboysdude
        cowboysdude Project Sponsor Module Developer last edited by cowboysdude

        Sam is a REALLY smart guy so he gives you the smart guy answer…
        I’m not as smart so I give you my dumb guy answer LOL

        It will work either way … so now you def have an answer that works 🙂

        S 1 Reply Last reply Reply Quote 1
        • S
          sdetweil @cowboysdude last edited by

          @cowboysdude said in MMM-MealViewer:

          Sam is a REALLY smart guy so he gives you the smart guy answer

          nah, Sam is the LAZY guy… change as LITTLE as possible. especially for folks just starting out

          1 Reply Last reply Reply Quote 1
          • G
            gonzonia last edited by

            Well, thanks to both of you! I can confirm it is finally working.

            Now to update github. Someday I should write some documentation too.

            1 Reply Last reply Reply Quote 0
            • htilburgs
              htilburgs last edited by

              @cowboysdude, I’m looking for the part where you “change” the XML data to JSON data. I’m trying to write a new MMM, but the data is presented in XML. I like the have it in JSON, so I can use it.

              Maybe I read over it, but I cannot figure out where you do this.

              S 1 Reply Last reply Reply Quote 0
              • S
                sdetweil @htilburgs last edited by sdetweil

                @htilburgs there are a few xml to json modules

                https://www.npmjs.com/package/xml2js

                google search
                ‘nodejs xmltojson’

                here is one with a just code, no extra libs

                https://davidwalsh.name/convert-xml-json

                1 Reply Last reply Reply Quote 0
                • htilburgs
                  htilburgs last edited by

                  @sdetweil , I’ve found them, but I don’t know how to use it in combination with the URL that creates the XML.

                  Indeed the last one with no extra libs looks promising. I tried to simply add this in the node_helper.js but getting stuck at how to use it.
                  I’ve looked into all the MMM Modules but cannot seem to find an example.

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    sdetweil @htilburgs last edited by sdetweil

                    @htilburgs the url bring back the data with request

                    request(url, function(err, res, body) {
                        // if no error and server was happy
                        if(err == null && res.statusCode ==200){
                        console.log(body);
                        var json_data=this.xmlToJson(body)
                        console.log("Speed[0] text is "+json_data.SD[0].SPEED.@attributes.TEXT)
                    }
                    });
                    

                    when the server responds, the function is called and passed the data, body)
                    and then u would convert it from xml to json . using the last code

                    var json_data=this.xmlToJson(body)

                    then the json is accessed with the normal structure notation
                    (using the sample with the code in the last link)

                    json_data.SD[0].SPEED.@attributes.TEXT will be ‘1421’

                    SD is an array (multiple of same xml tags)

                    a little ugly in the data layour, could get rid of the @attributes thing with a small code change

                    1 Reply Last reply Reply Quote 0
                    • htilburgs
                      htilburgs last edited by

                      So in my case the URL produces:

                      0_1576260496007_7fa5a24c-528a-4697-9557-2a9058df2860-image.png image url)

                      json_data.SD[0].SPEED@attributes.TEXT will be:

                      json.data.film[0].titel    --> 'Bellicher: Cel'
                      

                      Correct?

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        sdetweil @htilburgs last edited by

                        @htilburgs correct (json_data is the name of the output variable, note underscore, not dot, using dot means ‘go into’) … if you use one of the module add ons… not the code shown…

                        S 1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 3
                        • 4
                        • 5
                        • 4 / 5
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy