List Poem

by Matt Saul

HTML

<script src="https://voteforyou.co/js/poetry/suncalc.js"></script>

JavaScript

var marketLine, moonLine;



$(document).ready(function() {


  var d = new Date();
  
  // from sunCalc external library
  var sunTimes = SunCalc.getTimes(d, 42.963, -85.668); // GR

 console.log(sunTimes.sunset);
 
  if (d > sunTimes.sunrise && d < sunTimes.sunset) {
    day = true;
  } else {
    day = false;
  }

  // get market direction (channeled through one of my sites)
  url = 'https://voteforyou.co/Auxiliary/get_nasdaq_direction';
  $.get(url).done(function(response) {


    console.log('raw stock change ' + response);
    // start as string since +1 is not recognized as int
    num = response.toString();

    
    // remove + if present
    num = num.replace('+', '');

    // convert back to int
    num = parseInt(num);



    if (num < 0) {
      phrase = 'bear';
    } else {
      phrase = 'bull';
    }

    marketLine = 'coming off a ' + phrase + ' market';


    var d = new Date();


   moonPhaseData = SunCalc.getMoonIllumination(d);
   
   console.log(moonPhaseData);
   
   moonPhase = moonPhaseData.fraction;
   
   
    if (day == false) {
       moonLine = 'the moon shines outside my window';

      if (moonPhase < .01) {
        moonLine = 'on a moonless night';
      } else if (moonPhase >= 0.1 && moonPhase < 0.3) {
        moonLine = 'a crescent moon shines somewhere';
      } else if (moonPhase > .95) {
        moonLine = 'the full moon is tugging at me'
      }
    }
    else {
      moonLine = 'the day wears on';
    }



  });


  setTimeout(writePoem, 1600);


});


function writePoem() {
  document.write('1. ' + marketLine + '<br>');
  document.write('2. ' + moonLine + '<br>');
  
  var cc = new Date("Jan 20, 2021 00:00:00");
  var c = new Date();
  remaining = timeDifference(cc, c);

  document.write('3. we\'ve got at least ' + remaining + ' left of Trump in power<br>');
  document.write('4. our words are aggregated instead of illuminated');
}




// from http://jsfiddle.net/h8J8L/14/

function timeDifference(d, dd) {
   var  hour = 60...