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.

    read csv-data and put it in an array

    Scheduled Pinned Locked Moved Utilities
    313 Posts 3 Posters 495.6k Views 4 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.
    • PerlchampP Offline
      Perlchamp
      last edited by

      great, thanks !
      to your information:
      there are NO semikolons in your posted code. within them it goes !

      S 1 Reply Last reply Reply Quote 0
      • S Do not disturb
        sdetweil @Perlchamp
        last edited by

        @Perlchamp end of line ; are not required… I cut/pasted that code out of the running module

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • PerlchampP Offline
          Perlchamp
          last edited by

          without i have a black screen, with everythings fine.
          another information:
          age must be +1 but i think i will solve this alone. if not i’m too stuipid for this all :-)
          so i can create my table now. but i see:
          people who has birthday the same day:
          date should be displayed once, and the names in the same , separated by

          S 1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil @Perlchamp
            last edited by sdetweil

            @Perlchamp ok, I think you can fix those… age is a date diff()… add to results

            edit: age needs more work that just number… because they were comparing MONTH, but age was exact days.

            so I change my bd to may, but TODAY I am 68… in may i WILL BE 69 (in the future)
            so if TODAY or before, do NOT add one, if tomorrow or after (in the month) add 1

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 0
            • PerlchampP Offline
              Perlchamp
              last edited by

              i think, too. thanks very much, sam. I don’t know how to thank you Thank you very much !
              you’re great !
              and it is up to you whether you publish this module. I will not adorn myself with foreign feathers!

              S 2 Replies Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @Perlchamp
                last edited by

                @Perlchamp its not my module… its yours…

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • S Do not disturb
                  sdetweil @Perlchamp
                  last edited by

                  @Perlchamp see how interesting ‘just a birthday list’ can be! and u still have styles to apply etc

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 0
                  • PerlchampP Offline
                    Perlchamp
                    last edited by Perlchamp

                    I do not think so. I could never answer questions about any problems …
                    i did:

                    ... age='+(person.age + 1);
                    

                    the styles you could get from me, no problem. it’s just fair, isn’t it ?

                    S 1 Reply Last reply Reply Quote 0
                    • S Do not disturb
                      sdetweil @Perlchamp
                      last edited by

                      @Perlchamp should be wrong for people with birthday yesterday

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      1 Reply Last reply Reply Quote 0
                      • PerlchampP Offline
                        Perlchamp
                        last edited by Perlchamp

                        ah, oooook … hm. shooted to fast. but let me figured out by myself, cause i don’t wonna feel like a baby … i think if-statements and moment() could be helpfully.

                        1 Reply Last reply Reply Quote 0
                        • PerlchampP Offline
                          Perlchamp
                          last edited by Perlchamp

                          general question:
                          is there something like “print”? (for debugging) or have i use innerText or innerHTML or Log.log ? … to display something on screen ?

                          S 1 Reply Last reply Reply Quote 0
                          • S Do not disturb
                            sdetweil @Perlchamp
                            last edited by

                            @Perlchamp Log.log only

                            did u see my chat message about fixing a bug in the MMM-Logging module

                            Sam

                            How to add modules

                            learning how to use browser developers window for css changes

                            1 Reply Last reply Reply Quote 0
                            • PerlchampP Offline
                              Perlchamp
                              last edited by

                              i will have a look on it, though MERCI !

                              S 1 Reply Last reply Reply Quote 0
                              • S Do not disturb
                                sdetweil @Perlchamp
                                last edited by

                                @Perlchamp one other thing, u need to start a timer for when the month changes, when the timer expires, send a CONFIG message to the node_helper and it will send the latest birthdays list and everything will recalculate

                                Sam

                                How to add modules

                                learning how to use browser developers window for css changes

                                1 Reply Last reply Reply Quote 0
                                • PerlchampP Offline
                                  Perlchamp
                                  last edited by

                                  hi sam, yes i thought about. in the moment this is the actually file, though there is code annotate and at the wrong place, … just so you don’t wonder … :

                                  /* global Module */
                                  
                                  /* Magic Mirror
                                   * Module: birthdaylist
                                   *
                                   * Author: perlchamp@gmx.net
                                   * Lizenz: MIT
                                   */
                                  
                                  Module.register("birthdaylist", {
                                      // Default module config.
                                      defaults: {
                                  	
                                  	debugging: false,
                                  	initialLoadDelay: 0,		// How many seconds to wait on a fresh start up.
                                  					// This is to prevent collision with all other modules also
                                  					// loading all at the same time. This only happens once,
                                  					// when the mirror first starts up.
                                  	dimmEntries: true,   		// true: dims entries and the associated 
                                  					//       symbol when the date has expired.
                                  					// false: delete entries and the associated 
                                  					//        symbol when the date has expired.
                                  
                                  	language: "de",			// needed for dateformatting
                                  	updateDelay: 5		        // How many seconds after midnight before a refresh
                                  				        // This is to prevent collision with other modules refreshing
                                  				        // at the same time.
                                      },
                                  
                                      active_birthdays: {
                                  		
                                      },
                                  
                                  
                                      init: function() {
                                  	Log.log(this.name + " is in init!");
                                      },
                                  
                                      // Override start method
                                      start: function() {
                                  	Log.log("Starting module: " + this.name);
                                  
                                  	// set locale here, default: de
                                  	moment.locale(config.language);
                                  
                                  	// Calculate next midnight and add updateDelay
                                  	var now = moment();
                                  	this.midnight = moment([now.year(), now.month(), now.date() + 1]).add(this.config.updateDelay, "seconds");
                                  	this.loaded = false;
                                  	this.scheduleUpdate(this.config.initialLoadDelay * 1000);
                                      },
                                  
                                      loaded: function(callback) {
                                  	Log.log(this.name + " is loaded!");
                                  	callback();
                                      },
                                  
                                      // return list of other functional scripts to use, if any (like require in node_helper)
                                      getScripts: function () {
                                  	return ["moment.js"];
                                      },
                                   
                                      // return list of stylesheet files to use if any
                                      getStyles: function() {
                                  	return [this.data.path + "/css/bdl.css"];
                                      },
                                  
                                      // you can configure the heading of the list in config.js
                                      getHeader: function() {
                                  	return this.data.header;
                                      },
                                  
                                  
                                      // messages received from other modules and the system (NOT from your node helper)
                                      // payload is a notification dependent data structure
                                      notificationReceived: function(notification, payload, sender) {
                                  	// once everybody is loaded up
                                  	if(notification === "ALL_MODULES_STARTED") {
                                  	    // send our config to our node_helper
                                  	    this.sendSocketNotification("CONFIG",this.config);
                                  	}
                                  	if (sender) {
                                  	    Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
                                  	}
                                  	else {
                                  	    Log.log(this.name + " received a system notification: " + notification);
                                  	}
                                      },
                                  	
                                      // messages received from from your node helper (NOT other modules or the system)
                                      // payload is a notification dependent data structure, up to you to design between module and node_helper
                                      socketNotificationReceived: function(notification, payload) {
                                  	if(notification === "JSONDATA") {
                                  
                                  	    var self = this;
                                  	    Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
                                  			
                                  	    var now = moment();
                                  	    var day_month = moment().format("DD");
                                  	    
                                  	    for(var birthday of payload) {
                                  		// get 1st 5 chars of birthdate, thru month
                                  		// we will use this as the key in the hash
                                  		var birth_date = birthday.birth.substring(0,5);
                                  				
                                  		// get the birthday as a moment in this year, for comparing
                                  		var birth_date_moment = moment(birth_date + now.year(),"DD.MMYYYY");
                                  
                                  		// you can add days to a moment object and then compare 
                                  		//     if the birthdate is before that date (and after now)
                                  		//     so within the next xx days
                                  
                                  		// if the date is the same or later, don't use time of day
                                  		if(birth_date_moment.month() == now.month() ) {
                                  
                                  		    // birthday is in this month
                                  		    // check the hash if we've seen anything for today yet
                                  		    // if we haven't see this date yet
                                  		    if(this.active_birthdays[birth_date] == undefined) {
                                             
                                  			// create the holder for its info (array of 
                                  			//	names) in the hash
                                  			this.active_birthdays[birth_date] = [];
                                  		    }
                                  			
                                  		    // save the persons name on the list
                                  		    self.active_birthdays[birth_date].push({'name':birthday.name, 
                                  			'age': now.diff(moment(birthday.birth,'DD.MM.YYYY'), 'years') })
                                  		}
                                  	    }
                                       
                                  	    // tell MM to call and get our content
                                  	    self.updateDom();
                                  	}     			
                                      },
                                  
                                      // system notification your module is being hidden
                                      // typically you would stop doing UI updates (getDom/updateDom) if the module is hidden
                                      suspend: function() {
                                  
                                      },
                                  
                                      // system notification your module is being unhidden/shown
                                      // typically you would resume doing UI updates (getDom/updateDom) if the module is shown
                                      resume: function() {
                                  
                                      },
                                  
                                      // this is the major worker of the module, it provides the 
                                      // 	   displayable content for this module
                                      getDom: function() {
                                  	var self = this;
                                  	var wrapper = document.createElement("div");
                                  		
                                  	// tell MM to call and get our content
                                  	Log.log(JSON.stringify(this.active_birthdays))
                                  
                                  
                                  
                                  	if ((moment() > this.midnight) || (!this.loaded)) {
                                  	    var month = moment().month();
                                  	    var year = moment().year();
                                  //	    var monthName = moment().format("MMMM");
                                  //	    var monthLength = moment().daysInMonth();
                                  
                                  	    // tabelle erstellen
                                  	    var wrapper = document.createElement("table");
                                  	    wrapper.className = 'table';
                                  	    wrapper.id = 'birthday-table';
                                  
                                  	    // tabellenkopf erstellen
                                  	    var tHeader = document.createElement("thead");
                                  	    tHeader.className = "thead";
                                  	    tHeader.id = "birthday-thead";
                                  
                                  	    var headerTR = document.createElement("tr");
                                  	    headerTR.className = "tr-head";
                                  	    headerTR.id = "birthday-tr-head";			    
                                  
                                  	    var headerTH = document.createElement("th");
                                  	    headerTH.colSpan = "2";
                                  	    headerTH.scope = "col";
                                  	    headerTH.className = "th-head";
                                  	    headerTH.id = "birthday-th-head";
                                  	    headerTH.innerHTML = this.translate(this.config.title);
                                  	    headerTR.appendChild(headerTH);
                                  	    			
                                  	    tHeader.appendChild(headerTR);
                                  	    wrapper.appendChild(tHeader);
                                  		    
                                  	    // Create TFOOT section -- currently used for debugging only
                                  	    var tFooter = document.createElement('tfoot');
                                  	    tFooter.className = "tfoot";
                                  	    tFooter.id = "birthday-tfoot";
                                  
                                  	    var footerTR = document.createElement("tr");
                                  	    footerTR.className = "tr-foot";
                                  	    footerTR.id = "birthday-tr-foot";
                                  
                                  	    var footerTD = document.createElement("td");
                                  	    footerTD.colSpan ="2";
                                  	    footerTD.className = "td-foot";
                                  	    footerTD.id = "birthday-td-foot";
                                  	    if (this.config.debugging) {
                                  		footerTD.innerHTML = "Birthdaylist is currently in DEBUG mode!<br />Please see console log.";
                                  	    }
                                  	    else {
                                  		footerTD.innerHTML = "";
                                  	    }
                                  
                                  	    footerTR.appendChild(footerTD);
                                  	    tFooter.appendChild(footerTR);
                                  	    wrapper.appendChild(tFooter);
                                  
                                  
                                  
                                  
                                  
                                  
                                  	for(var birthday of Object.keys(this.active_birthdays)) {
                                  	    for(var person of this.active_birthdays[birthday]) {
                                  				
                                  		var m=document.createElement('div');
                                  				
                                  		// create tour table row here				
                                  		m.innerText = birthday + ' ' + person.name + ' age=' + person.age;
                                  		wrapper.appendChild(m);					
                                  	    }
                                  	}
                                  	
                                  	// pass the created content back to MM to add to DOM.
                                  	this.loaded = true;
                                  	return wrapper;
                                  
                                  /*
                                  			
                                  	    // Create TBODY section with day names
                                  	    var eintraege = 3;
                                  	    for (var i=1; i<=eintraege; i++) {
                                  		var tBody = document.createElement("tBody");
                                  		tBody.className = "tbody";
                                  		tBody.id = "birthday-tbody";
                                  
                                  		var bodyTR = document.createElement("tr");
                                  		bodyTR.className = "tr-body";
                                  		bodyTR.id = "birthday-tr-body";
                                  
                                  		var bodyTDimage = document.createElement("td");
                                  		bodyTDimage.className = "td-image";
                                  		bodyTDimage.id = "birthday-td-image";
                                  		bodyTDimage.innerHTML = "23";
                                  
                                  		var bodyTD = document.createElement("td");
                                  		bodyTD.className = "td-body";
                                  		bodyTD.id = "birthday-td-body";
                                  		bodyTD.innerHTML = "Bettina Zimmermann&nbsp;&nbsp;<span class=\"age-span\">46</span></br>Frank Dubiel&nbsp;&nbsp;<span class=\"age-span\">54</span></br>Jürgen Gruse&nbsp;&nbsp;<span class=\"age-span\">52</span>";
                                  
                                  
                                  //		var bodyAgeSpan = document.createElement("span");
                                  //		bodyAgeSpan.className = "age-span";
                                  //		bodyAgeSpan.id = "birthday-age-span";
                                  //		bodyAgeSpan.innerHTML = "&nbsp;&nbsp;46";
                                  //		bodyTD.appendChild(bodyAgeSpan);
                                  		
                                  
                                  		bodyTR.appendChild(bodyTDimage);
                                  		bodyTR.appendChild(bodyTD);
                                  		tBody.appendChild(bodyTR);
                                  		wrapper.appendChild(tBody);
                                  	    }
                                  */	
                                      },
                                      
                                      scheduleUpdate: function(delay) {
                                  	if (this.config.debugging) {
                                  	    Log.log("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
                                  	    Log.log("Birthdaylist IS IN DEBUG MODE!");
                                  	    Log.log("Remove 'debugging' option from config/config.js to disable.");
                                  	    Log.log("Current moment(): " + moment() + " (" + moment().format("hh:mm:ss a") + ")");
                                  	    Log.log("scheduleUpdate() delay set at: " + delay);
                                  	}
                                  
                                  	if (typeof delay !== "undefined" && delay >= 0) {
                                  	    nextReload = delay;
                                  	}
                                  
                                  	if (delay > 0) {
                                  	    // Calculate the time DIFFERENCE to that next reload!
                                  	    nextReload = moment.duration(nextReload.diff(moment(), "milliseconds"));
                                  	    if (this.config.debugging) {
                                  		var hours = Math.floor(nextReload.asHours());
                                  		var  mins = Math.floor(nextReload.asMinutes()) - hours * 60;
                                  		var  secs = Math.floor(nextReload.asSeconds()) - ((hours * 3600 ) + (mins * 60));
                                  		Log.log("  nextReload should happen at: " + delay + " (" + moment(delay).format("hh:mm:ss a") + ")");
                                  		Log.log("                  which is in: " + mins + " minutes and " + secs + " seconds.");
                                  		Log.log("              midnight set at: " + this.midnight + " (" + moment(this.midnight).format("hh:mm:ss a") + ")");
                                  		Log.log("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
                                  	    }
                                  	}
                                  
                                  	var self = this;
                                  	setTimeout(function() {
                                  	    self.reloadDom();
                                  	}, nextReload);
                                  
                                      },
                                  
                                      reloadDom: function() {
                                  	if (this.config.debugging) {
                                  	    Log.log("          Calling reloadDom()!");
                                  	}
                                  
                                  	var now = moment();
                                  	if (now > this.midnight) {
                                  	    this.updateDom(this.config.fadeSpeed * 1000);
                                  	    this.midnight = moment([now.year(), now.month(), now.date() + 1]).add(this.config.updateDelay, "seconds");
                                  	}
                                  
                                  	var nextRefresh = moment([now.year(), now.month(), now.date(), now.hour() + 1]);
                                  	this.scheduleUpdate(nextRefresh);
                                      }
                                      
                                  });
                                  

                                  and thanks agaibn for your time …

                                  S 1 Reply Last reply Reply Quote 0
                                  • S Do not disturb
                                    sdetweil @Perlchamp
                                    last edited by

                                    @Perlchamp awesome…

                                    Sam

                                    How to add modules

                                    learning how to use browser developers window for css changes

                                    1 Reply Last reply Reply Quote 0
                                    • PerlchampP Offline
                                      Perlchamp
                                      last edited by Perlchamp

                                      thanks :-)
                                      i although thought about to include a template, but first i want to figure out the html-stuff and the if … than -statements (people the same day, date passed, and so on …), but you see i’m on fire right now …

                                      S 1 Reply Last reply Reply Quote 0
                                      • S Do not disturb
                                        sdetweil @Perlchamp
                                        last edited by

                                        @Perlchamp cool… i did the age correction

                                        Sam

                                        How to add modules

                                        learning how to use browser developers window for css changes

                                        1 Reply Last reply Reply Quote 0
                                        • PerlchampP Offline
                                          Perlchamp
                                          last edited by Perlchamp

                                          cool too :-) , so you still burn, too :-))

                                          1 Reply Last reply Reply Quote 0
                                          • PerlchampP Offline
                                            Perlchamp
                                            last edited by

                                            hi sam, i know that the code of table is working (in testmodule). but can’t get objects in there. did look in dev-widow, but looks fine. in the terminal-window i see that objects have been handed over (node to module.js). this is the code for the body of the table:

                                            	    // create TBODY section with day names
                                            	    var tBody = document.createElement("tBody");
                                            	    tBody.className = "tbody";
                                            	    tBody.id = "birthday-tbody";
                                            	    
                                            	    for(var birthday of Object.keys(this.active_birthdays)) {
                                            		for(var person of this.active_birthdays[birthday]) {
                                            				
                                            		    //var m = document.createElement('div');
                                            				
                                            		    // create looped row section
                                            		    var bodyTR = document.createElement("tr");
                                            		    bodyTR.className = "tr-body";
                                            		    bodyTR.id = "birthday-tr-body";
                                            
                                            		    var bodyTDimage = document.createElement("td");
                                            		    bodyTDimage.className = "td-image";
                                            		    bodyTDimage.id = "birthday-td-image";
                                            		    bodyTDimage.innerHTML = birthday;
                                            
                                            		    var bodyTD = document.createElement("td");
                                            		    bodyTD.className = "td-body";
                                            		    bodyTD.id = "birthday-td-body";
                                            		    bodyTD.innerHTML = person.name + "<span class=\"age-span\">" + person.age + "</span>";
                                            		    				
                                            		    //m.innerText = birthday + ' ' + person.name + ' age=' + person.age;
                                            		    //wrapper.appendChild(m);
                                            		    
                                            		    bodyTR.appendChild(bodyTDimage);
                                            		    bodyTR.appendChild(bodyTD);
                                            		    tBody.appendChild(bodyTR);
                                            		    wrapper.appendChild(tBody);
                                            		    
                                            		}
                                            	    }
                                            

                                            what did i make wrong ?

                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 8
                                            • 9
                                            • 10
                                            • 11
                                            • 12
                                            • 15
                                            • 16
                                            • 10 / 16
                                            • 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