MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. ooom416354
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 14
    • Posts 95
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: NFL Score Module

      @strawberry-3.141 This is amazing! Is there the potential for other leagues like MLB or the NHL? Or perhaps selecting your favorite teams and only showing the scores?

      Great job nonetheless!

      posted in Sport
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 awesome, I will give it a shot. I can’t thank you enough! Much appreciated!

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 I had actually uploaded that file a few posts back. For reference here’s the entire thing (forgive the ugliness)

      <head>
      	<title>Magic Mirror</title>
      <html>
      	<style type="text/css">
      		<?php include('css/main.css') ?>
      		<?php include('css//mbta-icons.css') ?>
      	</style>
      	<link rel="stylesheet" type="text/css" href="css/weather-icons.css">
      	<script type="text/javascript">
      		var gitHash = '<?php echo trim(`git rev-parse HEAD`) ?>';
      	</script>
      	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
      	<meta name="google" value="notranslate" />
       
      </head>
      <body>
      
          <div class="backgroundTint"></div>
      
      	<div class="top left">
      		<div class="date small dimmed"></div>
      		<div class="time"></div>
      		<div class="timeWarning xxsmall"></div>
      		<div class="holidays xxsmall dimmed"></div>
      		<div class="calendar xxsmall"></div>
      		<div class="mbta xxxsmall dimmed"></div>
      	</div>
      
      	<div class="top right">
      	    <div class="windsun small dimmed"></div>
      		<div class="temp"></div>
      		<div class="tempfeelslike xxsmall"></div>
      		<div class="spacer"></div>
      		<div class="tempgraph"></div>
      		<div class="weekgraph"></div>
      		<div class="summary xxsmall2 dimmed"></div>
      		<div class="weatheralerts xxsmall2 dimmed"></div>
      	</div>
      
      	<div class="lower-third center-hor">
      		<div class="compliment light"></div>
      		<div class="weatherCompliment small light"></div>
      	</div>
      
      	<div class="bottom center-hor">
      		<div class="newsTitle xsmall xxdimmed"></div>
      		<div class="news medium"></div>
      	</div>
      
      	<div class="farbottom center-hor">
      		<div class="newsDots xxxsmall"></div>
      	</div>
      
      	<div class="farbottom right">
      		<div class="lastupdated luWeather xxxsmall xxdimmed"></div>
      		<div class="lastupdated luMBTA xxxsmall xxdimmed"></div>
      		<div class="lastupdated luRSS xxxsmall xxdimmed"></div>
      		<div class="lastupdated luHolidays xxxsmall xxdimmed"></div>
      	</div>
      
      </div>
      
      <!-- Third Parties -->
      <script src="js/jquery.js"></script>
      <script src="js/ical_parser.js"></script>
      <script src="js/moment-with-locales.js"></script>
      <script src="js/config.js"></script>
      <script src="js/rrule.js"></script>
      <script src="js/d3.js"></script>
      
      <!-- Our Stuff -->
      <script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
      <script src="js/mm-weather.js?nocache=<?php echo md5(microtime()) ?>"></script>
      <script src="js/mm-mbta.js?nocache=<?php echo md5(microtime()) ?>"></script>
      <script src="js/mm-mta.js?nocache=<?php echo md5(microtime()) ?>"></script>
      
      </html>
      </body>
      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 Just out of curiosity, if I were to add the code you provided into the PHP file, would i need to bracket it with <?php then add the code here?>

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 LOL - I’m just lost these days with all of this stuff. I should stick to my DB work.

      Let me see what I can do with the module documentation, it would be a good experience anyway to learn.

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 for reference here’s the full index.php file

      index.php

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 OK, so my PHP script is actually index.php, it’s effectively the page that loads and is my Mirror. In that file I have a reference to the JS file which runs the mta code.

      <script src="js/mm-mta.js"></script>

      So would I put the following in the PHP page? (sorry if I sound dumb here)

      var prev_datestamp = 0;
      var expire_time = 15 * 60 * 1000; // 15 minutes
      
      // run every five minutes
      if (file exists) {
        if (file.datestamp > previous_datestamp) {
      
         <script src="js/mm-mta.js"></script>
      
          previous_datestamp = file.datestamp;
        } else if (now > file.datestamp + expire_time) {
      
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script> 
            $("#mta").empty();
        </script>
      }
      }
      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 This is awesome!

      I would just put this in my JS file, right? I’m currently sending the following command through Tasker to the Pi so I think I’m good.

      touch curr-train.txt

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 Yup! That’s exactly what the setup is. The Pi is exposed to the internet via SSH on port 22, I changed the password to something pretty obscure but may look into additional security.

      Right now the JS script is running every 5 minutes and presenting the ETA for the train that is currently running closest to the actual time of the day. Problem here is that information clearly isn’t important because I’m at work and not in transit. I was trying to make it more robust in that I am able to use Tasker to ping cell towers and once I am in a specific location, output the file to the Pi to then trigger the script. Of course, if there is a better way I’d absolutely look into that, it was just my first thought on how to accomplish it.

      posted in General Discussion
      ooom416354O
      ooom416354
    • RE: Run JavaScript if a file is created

      @KirAsh4 the file wouldn’t have anything in it, it simply would trigger the mirror to display the current train status. The only reason I haven’t just sent a text directly from my phone when I hit a location is because there is no way for me to send the actual trains ETA (and if you’ve rode the MTA before it is always late). I was thinking I could display the results of my mta JS module (which does a JSON pull to their api getting the trains ETA) on the screen only when the file becomes available, thus having to avoid her looking at the mirror showing every trains ETA and only displaying my train. If you have any other suggestions I’d definitely like to try them out; like I said I’m doing this more to learn as well. Thanks!

      posted in General Discussion
      ooom416354O
      ooom416354
    • 1 / 1