METAR Grabber

Hello, everyone!

My weekend project; to create a working METAR grabber, that can take an XML document, such as this one from the FAA’s databases, and grab one XML element, to log it to the console.

Once this data is received, it will be implemented into a website called VATTASTIC that will read user input in the chat, and respond with a METAR. This piece of the puzzle is not the focus yet, and cannot be because I cannot access the data.

Here’s the code, and the error I’m getting:

Code:
https://jsfiddle.net/vzu1933y/

Error:
METARBot.js:1 Uncaught SyntaxError: Unexpected identifier

I tried a version editing InnerHTML as well, with the same result:

https://www.w3schools.com/code/tryit.asp?filename=FD5D938SJLBX

Any help would be appreciated. Thanks.

#Update

Found something about XML Schemas that might be messing with this? Still no explanation for the JavaScript error… Ideas?

I am not familiar with what you are working with, but I noticed one really simple thing. In your getTheXml function, you have an unnecessary semicolon before the closing parentheses. Just wanted to point that out.

I’ll take a look… Thanks.

1 Like

No cigar there… Will be rewriting this with the new JSON format they released recently, something I’m more comfortable with. Thanks for the help.

1 Like

Syntax errors should be fairly trivial to fix

Also, I suggest avoiding online “try it” apps, better use local files and open that in your browser, either by serving it with some http server (for example if you have python3 installed: python -m http.server in the site directory) or directly from the file system. Sharing the source is probably most conveniently done with a git repository, though a compressed archive would get the job done in a pinch

Just copied and pasted it onto the try it apps online from my local files so I didn’t have to paste raw code here. :wink:

I suspect your browser would point out exactly where the syntax error is if you peek in its console

It did…

I just couldn’t figure out what that meant. Now I fixed it. Thanks.

After fixing that (though it’s not that line is it) - you’ll run into issues with same origin policy - I’m kind of clueless on that but it might be that the request needs to be done server-side, (unless you can coax your users into disabling that security feature in their browser, which seems unlikely)

If they have a different api, then yeah. That could get around this. https://en.wikipedia.org/wiki/JSONP

If this application of yours is supposed to run on a server (if it doesn’t need to show the data on the same page that you are using to request the xml) then it has no business running in a browser anyhow, in which case this api seems just fine

$ curl 'https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&re
questType=retrieve&format=xml&stationString=PHTO&hoursBeforeNow=1'
<?xml version="1.0" encoding="UTF-8"?>
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
  <request_index>777069372</request_index>
  <data_source name="metars" />
  <request type="retrieve" />
  <errors />
  <warnings />
  <time_taken_ms>6</time_taken_ms>
  <data num_results="1">
    <METAR>
      <raw_text>PHTO 071353Z 23004KT 10SM FEW060 19/18 A2993 RMK AO2 SLP133 T01940178</raw_text>
      <station_id>PHTO</station_id>
      <observation_time>2017-03-07T13:53:00Z</observation_time>
      <latitude>19.72</latitude>
      <longitude>-155.05</longitude>
      <temp_c>19.4</temp_c>
      <dewpoint_c>17.8</dewpoint_c>
      <wind_dir_degrees>230</wind_dir_degrees>
      <wind_speed_kt>4</wind_speed_kt>
      <visibility_statute_mi>10.0</visibility_statute_mi>
      <altim_in_hg>29.929134</altim_in_hg>
      <sea_level_pressure_mb>1013.3</sea_level_pressure_mb>
      <quality_control_flags>
        <auto_station>TRUE</auto_station>
      </quality_control_flags>
      <sky_condition sky_cover="FEW" cloud_base_ft_agl="6000" />
      <flight_category>VFR</flight_category>
      <metar_type>METAR</metar_type>
      <elevation_m>12.0</elevation_m>
    </METAR>
  </data>
</response>

Thanks for the shot… I am, however, running it locally to run a bot myself. I don’t own the website nor server, so I’ll just be running the code myself.