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.

    Calendar Module: How to declare local calendar

    Scheduled Pinned Locked Moved Troubleshooting
    13 Posts 5 Posters 10.1k Views 5 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.
    • cowboysdudeC Offline
      cowboysdude Module Developer
      last edited by cowboysdude

      console.log(json.compliments.morning[0])

      I’m not programmer either but doesn’t this line just call the first object in the json file?

      function readTextFile(file, callback) {
      var rawFile = new XMLHttpRequest();
      rawFile.overrideMimeType(“application/json”);
      rawFile.open(“GET”, file, true);
      rawFile.onreadystatechange = function() {
      if (rawFile.readyState === 4 && rawFile.status == “200”) {
      callback(rawFile.responseText);
      }
      }
      rawFile.send(null);
      }

      //usage:
      readTextFile(“/Users/Documents/workspace/test.json”, function(text){
      var data = JSON.parse(text);
      console.log(data);
      });

      bheplerB 1 Reply Last reply Reply Quote 0
      • D Offline
        DazDavid @bhepler
        last edited by

        @bhepler thanks for the input but unfortunately your Problem is different to mine. The Calendar Module is already looking for an external ics File, all I need to know is the correct syntax for a local File instead of somewhere on a Webserver.

        1 Reply Last reply Reply Quote 0
        • yawnsY Offline
          yawns Moderator
          last edited by

          A quick search for “local ics” would return this: https://forum.magicmirror.builders/topic/467/calendar-ics-file-from-local-path/6 :)

          D 3 Replies Last reply Reply Quote 1
          • D Offline
            DazDavid @yawns
            last edited by

            @yawns hm Im pretty sure I searched for these two words before I opened the thread but didnt found it… I tried already something like this but without webcal prefix. I will try when I have a connection and give feedback. Thanks for the Link.

            1 Reply Last reply Reply Quote 0
            • D Offline
              DazDavid @yawns
              last edited by

              @yawns now I remember… i tried it that way and now the calendar tells me “no upcoming events”, whats not true.

              1 Reply Last reply Reply Quote 0
              • D Offline
                DazDavid @yawns
                last edited by

                @yawns Ok, the link finally solved my problem. I tried first to place the ics file under /MagicMirror directly but that doesnt work. As mentioned in the link I also created a new folder under /MagicMirror/modules and it works now. Thanks for your help.

                yawnsY 1 Reply Last reply Reply Quote 1
                • strawberry 3.141S Offline
                  strawberry 3.141 Project Sponsor Module Developer @bhepler
                  last edited by

                  @bhepler something like this should do the job:

                  move the call of complimentFile into the start method, you want to load that file only once not every 30 secs
                  then override the the config compliments object with your data, that should be it

                  start: function() {
                      Log.info("Starting module: " + this.name);
                  
                      this.lastComplimentIndex = -1;
                  		
                      this.complimentFile((response) => {
                          this.config.compliments = JSON.parse(response);
                      });
                  
                      // Schedule update timer.
                      var self = this;
                      setInterval(function() {
                          self.updateDom(self.config.fadeSpeed);
                      }, this.config.updateInterval);
                  },
                  

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

                  1 Reply Last reply Reply Quote 0
                  • yawnsY Offline
                    yawns Moderator @DazDavid
                    last edited by

                    @DazDavid
                    great, glad to help!

                    1 Reply Last reply Reply Quote 0
                    • bheplerB Offline
                      bhepler Module Developer @cowboysdude
                      last edited by bhepler

                      @cowboysdude said in Calendar Module: How to declare local calendar:

                      console.log(json.compliments.morning[0])

                      I’m not programmer either but doesn’t this line just call the first object in the json file?

                      Yes, it does. My test file has ten compliments loaded for each array (morning, afternoon & evening). That line was just to verify that I was getting a JSON object and not a file path. Which it does, meaning that I have the code reading from a local and parsing into a JSON object correctly. Now if I can just get that object in place of the default one, I’m golden.

                      @strawberry-3-141 said in Calendar Module: How to declare local calendar:

                      @bhepler something like this should do the job:
                      move the call of complimentFile into the start method, you want to load that file only once not every 30 secs
                      then override the the config compliments object with your data, that should be it

                      Well, nuts. I inserted this code and now the config.compliments is undefined. But I do think you’ve got me on the right track. Thanks!

                      compliments.js:67 Uncaught TypeError: Cannot read property 'length' of undefined
                      
                      bheplerB 1 Reply Last reply Reply Quote 0
                      • bheplerB Offline
                        bhepler Module Developer @bhepler
                        last edited by

                        Okay, thanks to @strawberry-3-141 expert advice, I have it up and running. The code he gave me is good, the JSON file I am loading from is not. We’ve got it sorted out and now I’m loading a compliment array from a file. Woohoo!

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • 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