Is there a way to show specific compliments on specific dates?



  • Hi,

    sorry if this is the wrong category for my question but the other categories don´t seem to fit either.

    I want to show messages on specific dates, like “Happy Birthday!” on my birthday. Those messages shall be shown just like regular compliments and in addition to the compliments. Is there an addon for the compliments module to achieve this?



  • I don’t know if there is one but you could very simply modify the compliment module to do so.
    just add

     if (moment().format('MMM D') == 'Apr 27')
         complimentText = "Happy birthday"
    

    to replace compliment by happy birthday on that date.
    In the getDom function under var complimentText = this.randomCompliment(); and you should good to go. just change the date to match your birthday. (it’s always the first 3 letter of the month. the first letter as to be capital. the number is 1 to 31 (not 01 or 02 or 03 etc… directly 1 or 2 or 3 …)

    You can add more if to add more specific message en specific date. you could also creat a new variable in the config array and compare the moment().format directly to that variable so you can set it up from the config file. You could even make that variable an array of date and encapsulate the if into a for and compare each date of that array to the moment().format so you can add as many date as you want.



  • @romain How to integrate the “Happy Birthday”-feature without using the compliments module? I mean i dont want to see such compliments, but on two specific dates i want to see the congratulations. how would i have to configure that module?

    ps:sorry for hijacking ;)



  • @romain said in Is there a way to show specific compliments on specific dates?:

    if (moment().format(‘MMM D’) == ‘Apr 27’)
    complimentText = “Happy birthday”

    Thank you for your help @romain !
    I tried it but it does not work.
    The config file of the compliments module now looks like this:

    // Override dom generator.
    getDom: function() {
    	var complimentText = this.randomCompliment();
    			if (moment().format('MMM D') == 'Apr 27')
       			 complimentText = "Happy birthday"
    	var compliment = document.createTextNode(complimentText);
    	var wrapper = document.createElement("div");
    	wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
    	wrapper.appendChild(compliment);
    
    	return wrapper;
    

    But the mirror shows only the normal compliments.

    Does this code add the birthday message to the normal compliments or does it replace them so that only happy birthday is shown on this day? If it is added, maybe I just need to wait longer until it is shown at random?

    I think I kind of understood what you explained in the last part, but I would not know how to do this, sorry. I think you described how I would be able to add dates in the config file of the mirror instead of the config of the compliments module, didn´t you? I would like to do this, would you mind explaining it a little more detailed?

    Thank you for your help!



  • @pauabaer

    as you can see I don´t know much about coding, but have you tried just deleting all the default compliments and then adding the line that romain suggested?



  • @CyanKali It should have replace all compliment. At that particular date.
    well, yesterday was the 26 right ? you let the 27 so I guess it just wasn’t the rigth date to activate.
    Try changing the date. (well, today must be the 27 so It should work today ahah).

    @pauabaer you could use the compliment module. add the thing I had and then go on the config.js file and replace all the compliments by empty strings so it will display nothing when not the date

                    {                                                                                                                                                                                                                            
                            module: "compliments",                                                                                                                                                                                               
                            position: "lower_third",                                                                                                                                                                                             
                            header: "",                                                                                                                                                                                                          
                            config: {                                                                                                                                                                                                            
                                    compliments: {                                                                                                                                                                                               
                                            anytime: [ "" ],                                                                                                                                                                                                   
                                            morning: [ "" ],                                                                                                                                                                                                   
                                            afternoon: [ "" ],                                                                                                                                                                                                   
                                            evening: [  "" ]                                                                                                                                                                                                    
                                    }                                                                                                                                                                                                            
                            }                                                                                                                                                                                                                    
                    },
    

    Or you could change the code so the module hide itself when the date isn’t right

            // Override dom generator.                                                                                                                                                                                                           
            getDom: function() {
                var complimentText = this.randomCompliment();
                if (moment().format('MMM D') == 'Apr 27')
                {
                    this.show();
                    complimentText = "Happy birthday"
                }
                else
                    this.hide();
                var compliment = document.createTextNode(complimentText);
                var wrapper = document.createElement("div");
                wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                wrapper.appendChild(compliment);
    
                    return wrapper;
            },
    


  • thanks @romain
    i think the second way will be mine. what do i have to write in the config.js file? how can i integrate a second date?



  • @pauabaer for the config file, you can just use the default one. we didn’t change much with that code.
    To add another date, just add as many else if () statement as needed. This isn’t a pretty solution but it will work.

            // Override dom generator.                                                                                                                                                                                                           
            getDom: function() {
                var complimentText = this.randomCompliment();
                if (moment().format('MMM D') == 'Apr 27')
                {
                    this.show();
                    complimentText = "Happy birthday"
                }
             else if (moment().format('MMM D') == 'Apr 28') {
                     this.show();
                    complimentText = "Happy 28th day"
    
             }  else
                    this.hide();
                var compliment = document.createTextNode(complimentText);
                var wrapper = document.createElement("div");
                wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                wrapper.appendChild(compliment);
    
                    return wrapper;
            },
    

    It’s not a pretty solution. I could made it prettier by creating a separate function with a while abd set a variable in the config section so you can add as many date as you want by editing the config.js. But I’m lazy so … yeah, not pretty solution.



  • yeah @romain. sounds for me as if this solution is very easy at all. you dont blow up the code with two more else if-statements.

    But with a separate function you could pimp up the module.
    Think about annual festivals like:

    • eastern --> Happy Eastern
    • christmas --> Merry Christmas
    • birthdays --> Happy Birthday

    etc.

    Perhaps you can overcome the laziness :grin:



  • @pauabaer Na, perhaps you can make it youself ;)
    It’s not that hard, just read about array and function in javascript.
    The idea is :
    -You creat a function.
    -You creat a variable in the config part. the variable should be an array. The easiest thing would be to make it an array of dictionnaries. So you can put a date and a message in each ones.
    -Inside the function you stock the value of moment().format(‘MMM D’) in a variable
    -Then you make a for that iterate on each element of the array an compare the value of moment().format(‘MMM D’) that you just got to the date part of each dictionary.
    -If there is a match, you return the associate message. if not, you just return an empty string.
    -In the getDom function you call that function instead of the randomCompliment

    And you should be fine.
    And hey, if you succeed you’ll could be proud to say you did a module yourself (sort of) !


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.