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.

    Can anyone revive AviationWX, PilotWX, or TAF

    Scheduled Pinned Locked Moved Unsolved Requests
    36 Posts 3 Posters 11.9k 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.
    • mumblebajM Offline
      mumblebaj Module Developer @sdetweil
      last edited by

      @sdetweil The below code works fine. Tested it. Having issues with my system at the moment and can’t make the changes. Can you incorporate?

      async function fetchData(metarUrl, airports) {
        try {
          const response = await axios.get(metarUrl, {
            responseType: 'arraybuffer', // ensure response is treated as binary
            headers: {
              'Accept-Encoding': 'gzip', // request gzip compression
            },
          });
      
          // Unzip the gzip response
          const unzippedData = zlib.gunzipSync(response.data).toString();
      
          let json_string = convert.toJson(unzippedData);
          var json = JSON.parse(json_string);
          var metarData = json.response.data.METAR;
          var airportData = new Object();
      
          var airports = payload.airportList.split(",").map(function (airport) {
              airport = airport.trim();
              return (airport.length < 4) ? "K" + airport : airport;
            });
      
          airports.forEach(function (airport) {
              metarData.forEach(function (metar) {
                  if (airport === metar.station_id) {
                      if (this.debug)
                          console.log("METAR data found for " + airport);
                      airportData[airport] = metar;
                      return; // check next airport in list
                  }
              });
              console.log(metarData)
          });
        } catch (error) {
          console.error('Error fetching data:', error);
        }
      }
      

      Check out my modules at: https://github.com/mumblebaj?tab=repositories
      Check my blog-post: https://mumblebaj.xyz/
      Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

      1 Reply Last reply Reply Quote 0
      • mumblebajM Offline
        mumblebaj Module Developer @sdetweil
        last edited by

        @sdetweil I can fix the other fetch as well no issues. Give me a few on this one.

        Check out my modules at: https://github.com/mumblebaj?tab=repositories
        Check my blog-post: https://mumblebaj.xyz/
        Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

        1 Reply Last reply Reply Quote 0
        • mumblebajM Offline
          mumblebaj Module Developer @sdetweil
          last edited by

          @sdetweil Both calls working.

          try {
                  const response = await axios.get(metarUrl, {
                      responseType: 'arraybuffer', // ensure response is treated as binary
                      headers: {
                          'Accept-Encoding': 'gzip', // request gzip compression
                      },
                  });
          
                  // Unzip the gzip response
                  const unzippedData = zlib.gunzipSync(response.data).toString();
          
                  let json_string = convert.toJson(unzippedData);
                  var json = JSON.parse(json_string);
                  var metarData = json.response.data.METAR;
                  var airportData = new Object();
          
                  var airports = payload.airportList.split(",").map(function (airport) {
                      airport = airport.trim();
                      return (airport.length < 4) ? "K" + airport : airport;
                  });
          
                  airports.forEach(function (airport) {
                      metarData.forEach(function (metar) {
                          if (airport === metar.station_id) {
                              if (this.debug)
                                  console.log("METAR data found for " + airport);
                              airportData[airport] = metar;
                              return; // check next airport in list
                          }
                      });
                      // console.log(metarData)
                  });
              } catch (error) {
                  console.error('Error fetching data:', error);
              }
          
              const checktype = { "Airspace_Flow_List":"Airspace_Flow", "Ground_Delay_List": "Ground_Delay", "Arrival_Departure_Delay_List": "Delay","Airport_Closure_List":"Airport" }
          
              
              try {
                  const response = await axios.get(FAAUrl);
          
                  // Your further processing
                  let json_string =
                      //convert.toJson(test_data)     swap comments to use test FAA data
                      convert.toJson(response.data.toString());
                  if (this.debug)
                      console.log("json faa=" + json_string);
                  const faa_data = JSON.parse(json_string);
          
                  if (!Array.isArray(faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type)) {
                      // save the current entry
                      const x = faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type
                      //  init as an array
                      faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type = []
                      // add the element into the array
                      faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type.push(x)
                  }
                  // loop thru the delay types
                  faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type.forEach(t => {
                      //
                      if (t.name !== "Airspace Flow Programs") {
                          // for each the  there are two major keys, name and the list for that type
                          // get the key of the list
                          const keyname = Object.keys(t)[1]
                          // remove the "_list"  part for passing to front end
                          const key = keyname.split('_').slice(0, -1).join('_')
                          if (this.debug)
                              console.log("key data=" + JSON.stringify(t[keyname][checktype[keyname]]) + "keyname=" + keyname + " key=" + checktype[keyname] + "\n")
                          if (!Array.isArray(t[keyname][checktype[keyname]])) {
                              const x = t[keyname][checktype[keyname]]
                              t[keyname][checktype[keyname]] = []
                              t[keyname][checktype[keyname]].push(x)
                          } else {
                              console.log("checkytype=" + checktype[keyname])
                          }
                          if (this.debug)
                              console.log("data=" + Object.keys(faa_data['AIRPORT_STATUS_INFORMATION'].Delay_type)[0] + " data=" + JSON.stringify(t) + " keyname=" + keyname + " key=" + key + " last part=" + JSON.stringify(t[keyname][key]) + "\n")
          
                          // look thru all the aaffected airports for this record type
                          t[keyname][checktype[keyname]].forEach(airport_record => {
                              // if the airport is one the user requested
                              if (airports.includes('K' + airport_record.ARPT)) {
                                  if (airportData['K' + airport_record.ARPT]['FAA'] == undefined)
                                      airportData['K' + airport_record.ARPT]['FAA'] = {}
                                  // save this data record
                                  airportData['K' + airport_record.ARPT]['FAA'][key] = airport_record
                              }
                          })
                      }
          
                  });
                  // Emitting data to Socket
                  //self.sendSocketNotification("WX_RESULT", airportData);
              } catch (error) {
                  console.error('Error fetching FAA data:', error);
              }
          

          Check out my modules at: https://github.com/mumblebaj?tab=repositories
          Check my blog-post: https://mumblebaj.xyz/
          Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

          S 1 Reply Last reply Reply Quote 0
          • S Do not disturb
            sdetweil @mumblebaj
            last edited by

            @mumblebaj thx. but there is a way to not have to use zlib. I just haven’t found any that work

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            mumblebajM 1 Reply Last reply Reply Quote 0
            • mumblebajM Offline
              mumblebaj Module Developer @sdetweil
              last edited by

              @sdetweil If you want to use fetch you can do the first call as follows.

              try {
                  const response = await fetch(metarUrl, {
                    headers: {
                      'Accept-Encoding': 'gzip', // Request gzip compression
                    },
                  });
              
                  if (!response.ok) {
                    throw new Error(`HTTP error! Status: ${response.status}`);
                  }
              
                  // Read response body as buffer
                  const buffer = await response.buffer();
              
                  // Manually decompress gzip data
                  const zlib = require('zlib');
                  const decompressedData = zlib.gunzipSync(buffer).toString();
              

              You could use pako.

              const decompressedData = pako.inflate(buffer, { to: 'string' });
              

              Check out my modules at: https://github.com/mumblebaj?tab=repositories
              Check my blog-post: https://mumblebaj.xyz/
              Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

              S 1 Reply Last reply Reply Quote 0
              • S Do not disturb
                sdetweil @mumblebaj
                last edited by sdetweil

                @mumblebaj but… you are not supposed to have to do either

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                mumblebajM 1 Reply Last reply Reply Quote 0
                • mumblebajM Offline
                  mumblebaj Module Developer @sdetweil
                  last edited by

                  @sdetweil I have not seen another way. Sorry…:man_facepalming:

                  Check out my modules at: https://github.com/mumblebaj?tab=repositories
                  Check my blog-post: https://mumblebaj.xyz/
                  Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                  F 1 Reply Last reply Reply Quote 0
                  • F Offline
                    FSAHD @mumblebaj
                    last edited by

                    @mumblebaj @sdetweil fwiw, and I don’t know if this would be any easier for the situation.

                    There is a site called avwx.rest
                    (I believe the pilot wx all was using that source)

                    It’s an API built solely for pilot data
                    You do need a key but maybe the data will be easier to pull?

                    https://avwx.docs.apiary.io/#

                    S 2 Replies Last reply Reply Quote 0
                    • S Do not disturb
                      sdetweil @FSAHD
                      last edited by

                      @FSAHD I might use that for pilot.

                      we are just talking about using more current support , so the module lasts longer

                      Sam

                      How to add modules

                      learning how to use browser developers window for css changes

                      mumblebajM 1 Reply Last reply Reply Quote 0
                      • mumblebajM Offline
                        mumblebaj Module Developer @sdetweil
                        last edited by

                        @sdetweil There is a simple api call from the site to get the metar data whicg might be simpler to use.

                        https://aviationweather.gov/api/data/metar?ids=KMCI%2CKORD%2CKBOS&format=json&taf=true&hours=1&bbox=-26.139%2C28.246&date=2024-03-10T23%3A44%3A22Z

                        Check out my modules at: https://github.com/mumblebaj?tab=repositories
                        Check my blog-post: https://mumblebaj.xyz/
                        Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                        1 Reply Last reply Reply Quote 1
                        • S Do not disturb
                          sdetweil @FSAHD
                          last edited by

                          @mumblebaj

                          thanks to your help I fixed the code to use the airport specific request which returns json and not gzip…

                          @FSAHD the output changed metar output changed again… sorry
                          i updated the sample text again

                          so git pull, and npm install

                          Sam

                          How to add modules

                          learning how to use browser developers window for css changes

                          F 1 Reply Last reply Reply Quote 0
                          • F Offline
                            FSAHD @sdetweil
                            last edited by

                            @sdetweil No worries. I really appreciate both of you alls help. Ill spend as much time I need on my end to get it up and going!

                            @mumblebaj thanks for adding your .02 cents to help this move forward.

                            Im new to this MM forum so I am not sure how to go about this but I would love to either get you both a cup of coffee or just donate to your efforts as a thank you!

                            S mumblebajM 2 Replies Last reply Reply Quote 0
                            • S Do not disturb
                              sdetweil @FSAHD
                              last edited by

                              @FSAHD I don’t accept donations.
                              I do this for fun and learning, so I’m already rewarded.

                              Sam

                              How to add modules

                              learning how to use browser developers window for css changes

                              1 Reply Last reply Reply Quote 0
                              • mumblebajM Offline
                                mumblebaj Module Developer @FSAHD
                                last edited by

                                @FSAHD No donations required. We love this project and this forum. :winking_face:

                                Check out my modules at: https://github.com/mumblebaj?tab=repositories
                                Check my blog-post: https://mumblebaj.xyz/
                                Check my MM Container: https://hub.docker.com/repository/docker/mumblebaj/magicmirror/general

                                1 Reply Last reply Reply Quote 0

                                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                With your input, this post could be even better 💗

                                Register Login
                                • 1
                                • 2
                                • 1 / 2
                                • First post
                                  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