https://github.com/bmonty/avweather
Swift package to process data from aviationweather.gov.
https://github.com/bmonty/avweather
aviation aviation-weather
Last synced: about 21 hours ago
JSON representation
Swift package to process data from aviationweather.gov.
- Host: GitHub
- URL: https://github.com/bmonty/avweather
- Owner: bmonty
- License: mit
- Created: 2020-01-19T20:21:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-31T14:10:03.000Z (over 2 years ago)
- Last Synced: 2025-04-18T12:08:09.843Z (about 2 months ago)
- Topics: aviation, aviation-weather
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AvWeather
AvWeather is a Swift package allowing you to retrieve and use data from the Aviation Weather Center at [aviationweather.gov](https://www.aviationweather.gov).
# Usage
(The example shows Metar, but TAF can be used as well)
```swift
import AvWeatherlet 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.
```swift
import AvWeatherlet 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)
```swift
// 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))")
}
```