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

    jyossarian

    @jyossarian

    0
    Reputation
    1
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    jyossarian Unfollow Follow

    Latest posts made by jyossarian

    • RE: NOAA Tide Chart for Today, Tomorrow, and Next Day

      So if chatgpt cannot write my code, I’m SOL?

      Can you think of any existing modules that can be edited (like weather) to get the desired result?

      posted in Development
      J
      jyossarian
    • NOAA Tide Chart for Today, Tomorrow, and Next Day

      Extreme noob here so be gentle.

      First, crice009 has created a module to pull NOAA tide data from a specific monitoring station and graph predicted vs actual data. I’m looking for something a little different. I’d like to see a simple chart consisting of the tide times and heights for three days pulled every night. Should I create a new module or fork off of crice009’s.

      I am reading the MM module building documentation but a LOT is going over my head.

      Reading some other posts, I got the idea to ask chatgpt to write the code I think I want. Tell me what you think.

      const axios = require('axios');
      const moment = require('moment');
      
      // Function to fetch tide data for a specific date
      async function fetchTideData(date) {
        try {
          const response = await axios.get('https://api.tidesandcurrents.noaa.gov/api/prod/datagetter', {
            params: {
              begin_date: date.format('YYYYMMDD'),
              end_date: date.format('YYYYMMDD'),
              station: '8722670',      // NOAA station ID for Port of West Palm Beach
              product: 'predictions',
              datum: 'MLLW',
              units: 'english',
              time_zone: 'lst_ldt',
              format: 'json',
            }
          });
          return response.data.predictions;
        } catch (error) {
          console.error('Error fetching tide data:', error);
          return [];
        }
      }
      
      // Function to display tide data for a specific date
      function displayTideData(date, tideData) {
        console.log(`High and Low Tides for Port of West Palm Beach (Date: ${date.format('YYYY-MM-DD')})`);
        console.log('--------------------------------------------------');
        console.log('| Time        | Type    | Height (feet) |');
        console.log('--------------------------------------------------');
        tideData.forEach(tide => {
          console.log(`| ${tide.t} | ${tide.type}   | ${tide.v}            |`);
        });
        console.log('--------------------------------------------------');
      }
      
      // Function to fetch and display tide data for today, tomorrow, and the following day
      async function fetchAndDisplayTideData() {
        const today = moment();
        for (let i = 0; i < 3; i++) {
          const date = today.clone().add(i, 'days');
          const tideData = await fetchTideData(date);
          displayTideData(date, tideData);
        }
      }
      
      // Main function to execute the program
      async function main() {
        await fetchAndDisplayTideData();
      }
      
      // Run the main function
      main();
      
      
      posted in Development
      J
      jyossarian