Giter VIP home page Giter VIP logo

avweather's Introduction

AvWeather

AvWeather is a Swift package allowing you to retrieve and use data from the Aviation Weather Center at aviationweather.gov.

Usage

(The example shows Metar, but TAF can be used as well)

import AvWeather

let avWeatherClient = AWCClient()

// send a request for METAR data for Boston Logan Airport (KBOS)
avWeatherClient.send(MetarRequest(forStation: "KBOS")) { response in 
    switch response {
    case .success(let metars):
        // do something with new METAR data
        print(metars[0].rawText)
        
    case .failure(let error):
        // request failed
        print(error.localizedDescription)
    }
}

// send a request for METAR data at multiple stations
avWeatherClient.send(MetarRequest(forStations: ["KBOS", "KORD", "KLAX"])) { response in
    switch response {
    case .success(let metars):
        // do something with new METAR data
        print(metars[0].rawText)
        
    case .failure(let error):
        // request failed
        print(error.localizedDescription)
    }
}

Sigmets

AWC distinguishes between international and US Sigmets. Both can be retrieved by AvWeather, and represented by one common Sigmet class, although with some different properties. Refer to the implementation in Sigmet.swift for details.

import AvWeather

let weatherClient = AWCClient()

//Configure the request for International or US Sigmets
weatherClient.send(SigmetRequest(type: .international)) { [weak self] response in
    DispatchQueue.main.async {
        switch response {
        case .success(let sigmets):
            //Do something with sigmets
            ...
            
        case .failure(let error):
            // request failed
            let msg = AWCClient.messageIn(error)
            print(msg)
        }
    }
}

Async/Await

AvWeather can also be used in Swift Async/Await concurrency schemes:

(The example shows TAF, but Metar and sigmets can be used as well)

// Instantiate a client
let client = AWCClient()
// Configure the request using 1 or more stations
let request = TAFRequest(forStations: ["ESSA", "ENGM", "GCLP", "LFPG", "KJFK", "KLAX"], mostRecent: true)
do {
    let tafs = try await client.send(request)
    // do something with TAF data
    print(tafs[0].rawText)
} catch {
    // An error was thrown
    print("Error thrown getting tafs: \(AWCClient.messageIn(error))")
}

avweather's People

Contributors

bmonty avatar jbergsee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.