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

folder monitor/ file creation...

Scheduled Pinned Locked Moved Requests
10 Posts 2 Posters 951 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.
  • B Offline
    banbutcher
    last edited by Apr 13, 2020, 10:44 AM

    @sdetweil

    i have it partly working… i have the contents displaying on my mirror but its all showing up on one line, how can i display it with each line break as in txt file?
    deluge.js:

    Module.register("deluge",{
    	defaults: {
    		updateInterval: 30 * 60 * 1000 //reads the file every 30 mins
    	},
    
    	start: function(){
    		this.sendSocketNotification("START", this.config);
    	},
    
    	socketNotificationReceived: function(notification, payload) {
    		if(notification === "DATA"){
    			this.dataFile = payload;
    			this.updateDom();
    		}
    	},
    
    	getDom: function(){
    		var wrapper = document.createElement("div");
    		if(this.dataFile){
    			wrapper.innerHTML = this.dataFile;
    		} else {
    			wrapper.innerHTML = "No data";
    		}
    		return wrapper;
    	}
    });
    

    and my node helper.js

    const NodeHelper = require("node_helper");
    const fs= require("fs");
    
    module.exports = NodeHelper.create({
    //here comes the part of the nodehelper after the 3 dots as posted above
    
    	socketNotificationReceived: function(notification, payload) {
    		if(notification === "START"){
    			this.config = payload;
    			this.readData();
        			setInterval(() => {
            			this.readData();
        			}, this.config.updateInterval);
    		}
    	},
    
    	readData: function(){
    		//to read a file to do the following
    		fs.readFile("new-tv-list.txt", "utf8", (err, data) => {
    			if (err) throw err;
    			this.sendSocketNotification("DATA", data);
    		});
    	}
    });
    

    thanks

    S 1 Reply Last reply Apr 13, 2020, 11:00 AM Reply Quote 0
    • S Away
      sdetweil @banbutcher
      last edited by Apr 13, 2020, 11:00 AM

      @banbutcher said in folder monitor/ file creation...:

        if(this.dataFile){
        	wrapper.innerHTML = this.dataFile;
        } else {
        	wrapper.innerHTML = "No data";
        }
      

      if the content you are injecting in NOT html, then you should use innerText…
      it might recognize the line ends as such… they are not line ends in html

      if the innerText doesn’t work, then u will have to convert the line ends t html line breaks
      replace '\n\ with ‘
      ’

      note that html is NOT UTF 8

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • B Offline
        banbutcher
        last edited by Apr 13, 2020, 11:18 AM

        here is the script that im using to retreve file names…

        #!/bin/bash
        
        TARGET=/media/TheVault/UnWatched/
        PROCESSED=/media/TheVault/Torrentopia/Torrent-Files/
        
        inotifywait -m -e create -e moved_to -r --format "%f" $TARGET \
                | while read FILENAME
                        do
                                echo Detected $FILENAME, Adding to list...
                                echo $FILENAME | cat - $PROCESSED/new-tv-list.txt > temp && mv temp $PROCESSED/new-tv-list.txt
        #                        echo $FILENAME `date` >> $PROCESSED/new-tv-list.txt
        			cp $PROCESSED/new-tv-list.txt /home/pi/MagicMirror/new-tv-list.txt
        
                        done
        

        if i take out the utf8 part i get an [object array buffer] instead of my file names…

        B S 2 Replies Last reply Apr 13, 2020, 11:26 AM Reply Quote 0
        • B Offline
          banbutcher @banbutcher
          last edited by banbutcher Apr 13, 2020, 11:28 AM Apr 13, 2020, 11:26 AM

          @banbutcher

          so i put back in the utf8 and then added <br> after i echo the filename and now its working fine now, i need to tweek it more to suit my needs but so far so good! thanks for your help @sdetweil im sure ill be asking more silly questions again soon! :)

          S 1 Reply Last reply Apr 13, 2020, 11:29 AM Reply Quote 0
          • S Away
            sdetweil @banbutcher
            last edited by Apr 13, 2020, 11:29 AM

            @banbutcher said in folder monitor/ file creation...:

            ill be asking more silly questions

            no such thing… ask away…

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 1
            • S Away
              sdetweil @banbutcher
              last edited by Apr 13, 2020, 11:31 AM

              @banbutcher you can also convert the buffer to a string

              buffer_object.toString()

              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
                9/10
                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