JQuery Marine Weather

Forums Requests JQuery Marine Weather

Viewing 1 reply thread
  • Author
    Posts
    • #20709
      Nichols Family
      Participant

      Alex;

      I have a autoupdating file located at;

      http://www.ndbc.noaa.gov/data/latest_obs/latest_obs.txt

      I want to pull the data from 42060 into a readable format so the result should be;

      weather for station “stn 42060” winds from “WDIR” at speed “WSPD” Wave height “WVHT”.

      do you have any ideas to get me started in the right path? I understand this is a text file but I have been unable to append and parse the data correctly. Thanks.

      Kevin

    • #20734
      Alexander Bautz
      Keymaster

      Hi,
      This URL throw this response when I try to get the file with ajax:

      Failed to load https://www.ndbc.noaa.gov/data/latest_obs/latest_obs.txt: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://spjsblog.sharepoint.com’ is therefore not allowed access.

      Do you control this datasoruce? – if you bring up the dev console and type in this (you need jQuery so you should run the code in the console from a DFFS enabled form):

      jQuery.get("https://www.ndbc.noaa.gov/data/latest_obs/latest_obs.txt", function( data ) {
          console.log(data)
      });

      Are you able to read it?

      If you do, I can help you parse it like this:

      var colDescr = [];
      jQuery.get("/path to the file/latest_obs.txt", function( data ) {
          jQuery.each(data.split("\n"),function(i,line){
      		if(i===1){
      			colDescr = line.split(/ +/);
      			colDescr[0] = "";
              }else{
      			var cols = line.split(/ +/);
      			console.log("Weather from station \""+ cols[0] + colDescr[0]+"\" winds from \""+ cols[8] + colDescr[8]+"\" at speed \""+ cols[9] + colDescr[9] +"\" Wave height \"" +cols[11] + colDescr[11] + "\"");
              }
          });		
      });

      This snippet outputs to the developer console like the attached image show.

      Alexander

      • This reply was modified 5 years, 11 months ago by Alexander Bautz. Reason: Added image
Viewing 1 reply thread
  • You must be logged in to reply to this topic.