How to use the metar.Metar function in metar

To help you get started, we’ve selected a few metar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-metar / python-metar / test / test_metar.py View on Github external
def test_020_parseStation_legal():
    """Check parsing of the station code."""
    assert Metar.Metar("KEWR").station_id == "KEWR"
    assert Metar.Metar("METAR KEWR").station_id == "KEWR"
    assert Metar.Metar("METAR COR KEWR").station_id == "KEWR"
    assert Metar.Metar("BIX1").station_id == "BIX1"
    assert Metar.Metar("K256").station_id == "K256"
github alanmitchell / bmon / bmsapp / calcs / internetwx.py View on Github external
# try 3 times in case of download errors.
        for i in range(3):
            try:
                read_str = urllib.request.urlopen(
                    URL % stnCode).read().decode('utf-8')
                break
            except:
                # wait before retrying
                time.sleep(1)

        if 'read_str' not in locals():
            # retries must have failed if there is no 'read_str' variable.
            raise Exception('Could not access %s.' % stnCode)

        # second line onward
        obs = Metar.Metar('\n'.join(read_str.splitlines()[1:]))
        _nws_cache.store(stnCode, obs)

    return obs
github python-metar / python-metar / get_report.py View on Github external
if not stations:
    usage()

for name in stations:
    url = "%s/%s.TXT" % (BASE_URL, name)
    if debug:
        sys.stderr.write("[ " + url + " ]")
    try:
        urlh = urlopen(url)
        report = ""
        for line in urlh:
            if not isinstance(line, str):
                line = line.decode()  # convert Python3 bytes buffer to string
            if line.startswith(name):
                report = line.strip()
                obs = Metar.Metar(line)
                print(obs.string())
                break
        if not report:
            print("No data for ", name, "\n\n")
    except Metar.ParserError as exc:
        print("METAR code: ", line)
        print(string.join(exc.args, ", "), "\n")
    except:
        import traceback

        print(traceback.format_exc())
        print("Error retrieving", name, "data", "\n")
github joanpc / XplaneNoaaWeather / noaweather / weatherServer.py View on Github external
print "Can't bind address: %s, port: %d." % ("localhost", conf.server_port)

        if conf.weatherServerPid is not False:
            print 'Killing old server with pid %d' % conf.weatherServerPid
            os.kill(conf.weatherServerPid, signal.SIGTERM)
            time.sleep(2)
            conf.serverLoad()
            server = SocketServer.UDPServer(("localhost", conf.server_port), ClientHandler)

    # Save pid
    conf.weatherServerPid = os.getpid()
    conf.serverSave()

    # Weather classes
    gfs = GFS(conf)
    metar = Metar(conf)
    wafs = WAFS(conf)

    # Init worker thread
    worker = Worker([gfs, metar, wafs], conf.parserate)
    worker.start()

    print 'Server started.'

    # Server loop
    try:
        server.serve_forever()
    except KeyboardInterrupt:
        pass

    # Close gfs worker and save config
    worker.shutdown()
github python-metar / python-metar / parse_metar.py View on Github external
def process_line(line):
    """Decode a single input line."""
    line = line.strip()
    if len(line) and line[0] == line[0].upper():
        try:
            obs = Metar.Metar(line)
            if report:
                print("--------------------")
                print(obs.string())
        except Metar.ParserError as exc:
            if not silent:
                print("--------------------")
                print("METAR code: ",line)
                print(", ".join(exc.args))
github akrherz / iem / scripts / ingestors / madis / extract_hfmetar.py View on Github external
iem.data["phour"] = float(round(val, 2))
                mtr += "P%04i " % (iem.data["phour"] * 100.0,)
            elif val > 0:
                # Trace
                mtr += "P0000 "
                iem.data["phour"] = TRACE_VALUE

        if tgroup != "T":
            mtr += "%s " % (tgroup,)

        if autoremarks[i] != "" or opremarks[i] != "":
            mtr += "%s %s " % (autoremarks[i], opremarks[i])
        mtr += "MADISHF"
        # Eat our own dogfood
        try:
            Metar.Metar(mtr)
            iem.data["raw"] = mtr
        except Exception as exp:
            print("dogfooding extract_hfmetar %s resulted in %s" % (mtr, exp))
            continue

        for key in iem.data:
            if isinstance(iem.data[key], np.float32):
                print("key: %s type: %s" % (key, type(iem.data[key])))
        icursor = pgconn.cursor()
        if not iem.save(icursor, force_current_log=True, skip_current=True):
            print(
                ("extract_hfmetar: unknown station? %s %s %s\n%s")
                % (sid3, network, ts, mtr)
            )

        icursor.close()