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

New to this and have no idea how to implement this module, MMM-RottenTomatoes

Scheduled Pinned Locked Moved Tutorials
5 Posts 3 Posters 467 Views 3 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.
  • D Offline
    Datfatboi
    last edited by Dec 26, 2020, 3:30 AM

    Hey, I’m building my first magic mirror and so far I have added a weather and commute module. I’m now trying to add a module that will show me information about upcoming movies like box office and ratings. I found the module MMM-RotenTomatoes and have downloaded the rt-scraper and GitHub CLI but I have no idea what to do after that. I have absolutely no idea what to put in that config file for it work. Can anyone help?

    https://github.com/AdamMoses-GitHub/MMM-RottenTomatoes/blob/master/MMM-RottenTomatoes.js

    S 1 Reply Last reply Dec 26, 2020, 4:13 AM Reply Quote 0
    • S Away
      sdetweil @Datfatboi
      last edited by sdetweil Dec 26, 2020, 4:39 AM Dec 26, 2020, 4:13 AM

      @Datfatboi all the config is on this page
      https://github.com/AdamMoses-GitHub/MMM-RottenTomatoes

      read the two links in my signature

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      D 1 Reply Last reply Dec 26, 2020, 6:03 AM Reply Quote 0
      • D Offline
        Datfatboi @sdetweil
        last edited by sdetweil Dec 26, 2020, 2:57 PM Dec 26, 2020, 6:03 AM

        @sdetweil
        I guess a better Question would be, in the config file is it supposed to look like this:

        modules: [
        		{
            			module: "MMM-RottenTomatoes",
            			position: "top_left",
            			config: {
        			showHeader: "true"
        			showBoxOffice: "true"
        			showOpeningThisWeek: "true"
            		}
        		},
        

        OR something like this:

        Module.register("MMM-RottenTomatoes", {
        	// setup the default config options
        	defaults: {		
        		// optional
        		showHeader: true,
        		showOpeningThisWeek: true,
        		showBoxOffice: true,
        		showComingSoon: true,
        		limitOpeningThisWeek: 3,
        		limitBoxOffice: 3,
        		limitComingSoon: 3,
        		boxOfficeAfter: true,
        		mergeOpeningAndComingSoon: true,
        	},
        	// the start function
        	start: function() {
        		// log starting
        		Log.info("Starting module: " + this.name);
        		// set refresh rate to 6 hours
        		this.config.refreshRate = 6 * 60 * 60 * 1000;
                // set an identier config tag
        		this.config.identifier = this.identifier;
        		// set loaded, error, and the update to init values
        		this.loaded = false;
        		this.errorMessage = null;
        		// set the header to this place
                if (this.config.showHeader) {    
                    this.data.header = 'Rotten Tomatoes';
                }
        		if (this.config.limitOpeningThisWeek == 0)
        			this.config.limitOpeningThisWeek = 100;
        		if (this.config.limitBoxOffice == 0)
        			this.config.limitBoxOffice = 100;
        		if (this.config.limitComingSoon == 0)
        			this.config.limitComingSoon = 100;
                // add this config to the helper functions
        		this.sendSocketNotification('ROTTEN_TOMATOES_REGISTER_CONFIG', this.config);
        	},
        	// the socket handler
        	socketNotificationReceived: function(notification, payload) {
        		// if an update was received
        		if (notification === "ROTTEN_TOMATOES_UPDATE") {
        			// check this is for this module based on the woeid
        			if (payload.identifier === this.identifier)
        			{
        				// set loaded flag, set the update, and call update dom                
        				this.rtData = payload.rtData;
                        this.loaded = true;
                        this.updateDom();
        			}
        		}
                // if sent error notice
                if (notification === "ROTTEN_TOMATOES_TOO_MANY_ERRORS") {
                    this.errorMessage("There was an error.");
                    if (this.updateTimer !== null)
                        clearTimeout(this.updateTimer);
                    this.updateTimer = null;
                    this.updateDom();
                }
        	},
        	//
        	cleanScore: function(theScore) {
        		if (theScore.indexOf('%') == -1)
        			return '--';
        		else
        			return theScore;
        	},
        	//
        	cleanTitle: function(theTitle) {
        		if (theTitle.length > 28)
        			return theTitle.slice(0, 28) + '...';
        		else
        			return theTitle;
        	},
        	// the get dom handler
        	getDom: function() {
                // if an error, say so
                if (this.errorMessage !== null) {
                    var wrapper = document.createElement("div");
        			wrapper.className = "small";
        			wrapper.innerHTML = this.errorMessage;
        			return wrapper;	
                }
        		// if nothing loaded yet, put in placeholder text
        		if (!this.loaded) {
        			var wrapper = document.createElement("div");
        			wrapper.className = "small";
        			wrapper.innerHTML = "Awaiting Update...";
        			return wrapper;			
        		}
        		var titleSize = 'xsmall';
        		var movieSize = 'xsmall';
        		var wrapper = document.createElement("table");
        		// do opening this week
        		var allOTWandCSRows = [ ];
        		if (this.config.showOpeningThisWeek) {
        			var otwData = this.rtData.openingThisWeek;
        			var otwTitleTR = document.createElement("tr");
        			otwTitleTR.className = titleSize;
        			var otwTitleTD = document.createElement("td");
        			otwTitleTD.innerHTML = "Opening This Week";
        			if (this.config.mergeOpeningAndComingSoon)
        				otwTitleTD.innerHTML = "Opening / Coming Soon";
        			otwTitleTD.colSpan = "3";
        			otwTitleTR.appendChild(otwTitleTD);
        			allOTWandCSRows.push(otwTitleTR);
        			for (var cIndex = 0; 
        					(cIndex < otwData.length) && (cIndex < this.config.limitOpeningThisWeek); 
        					cIndex++) {
        				var cOTW = otwData[cIndex];
        				var otwRowTR = document.createElement("tr");	
        				otwRowTR.className = movieSize;
        				var otwRowMeter = document.createElement("td");
        				otwRowMeter.innerHTML = this.cleanScore(cOTW.meter) + "&nbsp;&nbsp;";
        				otwRowTR.appendChild(otwRowMeter);
        				var otwRowTitle = document.createElement("td");
        				otwRowTitle.innerHTML = this.cleanTitle(cOTW.title) + "&nbsp;&nbsp;";
        				otwRowTitle.align = 'left';
        				otwRowTR.appendChild(otwRowTitle);
        				var otwRowDate = document.createElement("td");
        				otwRowDate.innerHTML = "&nbsp;&nbsp;" + cOTW.date;
        				otwRowTR.appendChild(otwRowDate);
        				allOTWandCSRows.push(otwRowTR);
        			}
        		}
        		// do opening this week
        		if (this.config.showOpeningThisWeek) {
        			var csData = this.rtData.comingSoon;
        			var csTitleTR = document.createElement("tr");
        			csTitleTR.className = titleSize;
        			var csTitleTD = document.createElement("td");
        			csTitleTD.innerHTML = "Coming Soon";
        			csTitleTD.colSpan = "3";
        			csTitleTR.appendChild(csTitleTD);
        			if (!this.config.mergeOpeningAndComingSoon)
        				allOTWandCSRows.push(csTitleTR);
        			for (var cIndex = 0; 
        					(cIndex < csData.length) && (cIndex < this.config.limitComingSoon); 
        					cIndex++) {
        				var ccs = csData[cIndex];
        				var csRowTR = document.createElement("tr");	
        				csRowTR.className = movieSize;
        				var csRowMeter = document.createElement("td");
        				csRowMeter.innerHTML = this.cleanScore(ccs.meter) + "&nbsp;&nbsp;";
        				csRowTR.appendChild(csRowMeter);
        				var csRowTitle = document.createElement("td");
        				csRowTitle.innerHTML = this.cleanTitle(ccs.title) + "&nbsp;&nbsp;";
        				csRowTitle.align = 'left';
        				csRowTR.appendChild(csRowTitle);
        				var csRowDate = document.createElement("td");
        				csRowDate.innerHTML = "&nbsp;&nbsp;" + ccs.date;
        				csRowTR.appendChild(csRowDate);
        				allOTWandCSRows.push(csRowTR);
        			}	
        		}		
        		// do box office
        		var boRows = [ ];
        		if (this.config.showBoxOffice) {
        			var boData = this.rtData.boxOffice;
        			var boTitleTR = document.createElement("tr");
        			boTitleTR.className = titleSize;
        			var boTitleTD = document.createElement("td");
        			boTitleTD.innerHTML = "Box Office";
        			boTitleTD.width = "250px";
        			boTitleTD.colSpan = "3";
        			boTitleTR.appendChild(boTitleTD);
        			boRows.push(boTitleTR);
        			for (var cIndex = 0; 
        					(cIndex < boData.length) && (cIndex < this.config.limitBoxOffice); 
        					cIndex++) {
        				var cbo = boData[cIndex];
        				var boRowTR = document.createElement("tr");	
        				boRowTR.className = movieSize;
        				var boRowMeter = document.createElement("td");
        				boRowMeter.innerHTML = this.cleanScore(cbo.meter) + "&nbsp;&nbsp;";
        				boRowTR.appendChild(boRowMeter);
        				var boRowTitle = document.createElement("td");
        				boRowTitle.innerHTML = this.cleanTitle(cbo.title) + "&nbsp;&nbsp;";
        				boRowTitle.align = 'left';
        				boRowTR.appendChild(boRowTitle);
        				var boRowGross = document.createElement("td");
        				boRowGross.innerHTML = "&nbsp;&nbsp;" + cbo.gross;
        				boRowTR.appendChild(boRowGross);
        				boRows.push(boRowTR);
        			}
        		}
        		// build the table
                var allRows = [ ];
                // if set to show box office first, do that
        		if (!this.config.boxOfficeAfter)
        			allRows = allRows.concat(boRows);
                // add opening this week and coming soon rows
        		allRows = allRows.concat(allOTWandCSRows);
                // if set to show box office after, do that
        		if (this.config.boxOfficeAfter)
        			allRows = allRows.concat(boRows);
                // add all rows to the return table wrapper
        		for (var cIndex = 0; cIndex < allRows.length; cIndex++) {
        			wrapper.appendChild(allRows[cIndex]);
        		}
                // return table wrapper
        		return wrapper;	
        	}
        });
        
        mumblebajM S 2 Replies Last reply Dec 26, 2020, 12:42 PM Reply Quote 0
        • mumblebajM Offline
          mumblebaj Module Developer @Datfatboi
          last edited by Dec 26, 2020, 12:42 PM

          @Datfatboi You should only add the following to your config.js

          {
          module: “MMM-RottenTomatoes”,
          position: “top_left”,
          config: {
          showHeader: “true”
          showBoxOffice: “true”
          showOpeningThisWeek: “true”
          }
          },
          

          Check out my modules at: https://github.com/mumblebaj?tab=repositories

          1 Reply Last reply Reply Quote 0
          • S Away
            sdetweil @Datfatboi
            last edited by sdetweil Dec 26, 2020, 3:01 PM Dec 26, 2020, 1:12 PM

            @Datfatboi never change the module code ( your second choice)
            unless u are fixing a bug or adding some new function.

            always put info into config.js

            now, your lines for config.js are not correct.

            {
            	module: "MMM-RottenTomatoes",
            	position: "top_left",
            	config: {
            		showHeader: "true"
            		showBoxOffice: "true"
            		showOpeningThisWeek: "true"
            	}
            },
            

            watch out for the quote style… the curved ones are used by MS office apps…
            we need the text ones, straight up and down

            also u are missing some required trailing commas
            look at each line, and follow the rules

            general rules for module definition
            {} and [] must be matched
            the word to the left of : does not need quotes
            the thing to the right of : if a number or, true/false does NOT need quotes
            otherwise is needs quotes, single or double doesn’t matter as long as start and end quote are the same

            if the thing on the next line is a word , then THIS line needs a trailing comma
            if the thing on the next line is {, then THIS line needs a trailing comma

            also, indentation makes it MUCH easier to see the {} and []

            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
              3/5
              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