Пример #1
0
            "PO": 27,
            "SQ": 27,
            "FC": 27,
            "SS": 27,
            "DS": 27,
        }

        return condicodes.get(str(code), None)

    except BaseException:
        return None


# Get ICAO stations
stations = pd.read_sql(
    "SELECT `id`, `icao` FROM `stations` WHERE `icao` IS NOT NULL", jsp.db())

stations = stations.set_index("icao")

# Get cycle
cycle = (datetime.now() - timedelta(hours=2)).strftime("%H")

# Create request for JSON file
url = f"https://tgftp.nws.noaa.gov/data/observations/metar/cycles/{cycle}Z.TXT"
req = request.Request(url)

# Get METAR strings
with request.urlopen(req) as raw:
    file = raw.read().decode(errors="ignore").splitlines()

data = []
Пример #2
0
if len(stations) < STATIONS_PER_CYCLE:
    jsp.set_var("station_counter", 0)
    sys.exit()
else:
    jsp.set_var("station_counter", counter + STATIONS_PER_CYCLE)

for station_file in stations:
    try:
        # Get national weather station ID
        national_id = (str(station_file[-13:-8])
                       if MODE == "recent" else str(station_file[-32:-27]))
        station = pd.read_sql(
            f"""
            SELECT `id` FROM `stations` WHERE `national_id` LIKE "{national_id}"
            """,
            jsp.db(),
        ).iloc[0][0]

        # DataFrame which holds data for one weather station
        df_station = None

        # Go through all parameters
        for parameter in PARAMETERS:
            try:
                remote_file = find_file(parameter["dir"], national_id)

                if remote_file is not None:
                    file_hash = hashlib.md5(
                        remote_file.encode("utf-8")).hexdigest()
                    local_file = os.path.dirname(__file__) + os.sep + file_hash
                    with open(local_file, "wb") as f: