commit 67e87e973171e33668a6708132bf7f467355686d Author: Zoe Moore Date: Mon Mar 28 19:24:48 2022 -0700 Initial commit diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..f40bc03 --- /dev/null +++ b/main.qml @@ -0,0 +1,46 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.0 as Controls +import QtQuick.Layouts 1.2 +import org.kde.kirigami 2.13 as Kirigami + +// Base element, provides basic features needed for all kirigami applications +Kirigami.ApplicationWindow { + // ID provides unique identifier to reference this element + id: root + title: "Metar Weather" + + // Initial page to be loaded on app load + pageStack.initialPage: Kirigami.Page { + actions { + main: Kirigami.Action { + icon.name: "refresh" + text: "Refresh" + onTriggered: logic.refresh() + } + right: Kirigami.Action { + icon.name: "plus" + text: "Add Airport" + onTriggered: addAirport.open() + } + } + } + Kirigami.OverlaySheet { + id: addAirport + + Kirigami.FormLayout { + Controls.TextField { + id: airportCode + Kirigami.FormData.label: "airport code" + } + Controls.Button { + text: "Add" + onClicked: { + logic.addAirport(airportCode.text) + addAirport.close() + } + } + } + } + +} + diff --git a/metar b/metar new file mode 100755 index 0000000..5f674fa Binary files /dev/null and b/metar differ diff --git a/metar.nim b/metar.nim new file mode 100644 index 0000000..91e22ed --- /dev/null +++ b/metar.nim @@ -0,0 +1,96 @@ +import std/[httpclient, times, xmlparser, xmltree] +import strformat +import NimQml +import macros +import typeinfo + +proc getMetar(client: HttpClient, code: string): XMLNode = + let requestUrl = &"https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString={code}" + let metarData = client.getContent(requestUrl) + parseXml(metarData) + +proc childString(node: XMLnode, name: string): string = + node.child(name).innerText + +type SkyCondition = object + skyCover: string + cloudBaseAgl: string + +type MetarData = object + rawText: string + stationId: string + observationTime: string + temperature: string + dewPoint: string + windHeading: string + windSpeedKnots: string + visibility: string + altimiter: string + flightCategory: string + skyConditions: seq[SkyCondition] + +proc fromXml*(xmlData: XMLNode): MetarData = + let metar = xmlData.child("data").child("METAR") + + result = MetarData( + rawText: metar.childString("raw_text"), + stationId: metar.childString("station_id"), + observationTime: metar.childString("observation_time"), + temperature: metar.childString("temp_c"), + dewPoint: metar.childString("dewpoint_c"), + windHeading: metar.childString("wind_dir_degrees"), + visibility: metar.childString("wisibility_statute_mi"), + altimiter: metar.childString("altim_in_hg"), + flightCategory: metar.childString("flight_category") + ) + + for skyConditionXml in metar.findAll("sky_condition"): + result.skyConditions.add( + SkyCondition( + skyCover: skyConditionXml.attr("sky_cover"), + cloudBaseAgl: skyconditionXml.attr("cloud_base_ft_agl"))) + +QtObject: + type ApplicationLogic* = ref object of QObject + app: QApplication + + proc delete*(self: ApplicationLogic) = + self.QObject.delete + + proc setup(self: ApplicationLogic) = + self.QObject.setup + + proc newApplicationLogic*(app: QApplication): ApplicationLogic = + new(result) + result.app = app + result.setup() + + ## Real methods below here + + proc refresh(self: ApplicationLogic) {.slot.} = + echo "Refresh called" + + proc addAirport(self: ApplicationLogic, code: string) {.slot.} = + echo &"Add airport called {code}" + + proc deleteAirport(self: ApplicationLogic, code: string) {.slot.} = + echo &"Delete {code}" + +proc mainProc() = + let app = newQApplication() + defer: app.delete() + + let engine = newQQmlApplicationEngine() + defer: engine.delete() + + let logic = newApplicationLogic(app) + let logicVariant = newQVariant(logic) + + engine.setRootContextProperty("logic", logicVariant) + engine.load("main.qml") + app.exec() + +when isMainModule: + mainProc() + GC_fullcollect() + diff --git a/metar.xml b/metar.xml new file mode 100644 index 0000000..14aa9cf --- /dev/null +++ b/metar.xml @@ -0,0 +1,34 @@ + + 6914747 + + + + + 6 + + + KOAK 260253Z 28014KT 10SM FEW010 FEW120 FEW180 12/08 A2999 RMK AO2 SLP155 T01220078 55002 + KOAK + 2022-03-26T02:53:00Z + 37.72 + -122.23 + 12.2 + 7.8 + 280 + 14 + 10.0 + 29.991142 + 1015.5 + + TRUE + + + + + VFR + -0.2 + METAR + 3.0 + + +