Initial commit
This commit is contained in:
46
main.qml
Normal file
46
main.qml
Normal file
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
96
metar.nim
Normal file
96
metar.nim
Normal file
@@ -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()
|
||||||
|
|
||||||
34
metar.xml
Normal file
34
metar.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<response version="1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.aviationweather.gov/static/adds/schema/metar1_2.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<request_index>6914747</request_index>
|
||||||
|
<data_source name="metars" />
|
||||||
|
<request type="retrieve" />
|
||||||
|
<errors />
|
||||||
|
<warnings />
|
||||||
|
<time_taken_ms>6</time_taken_ms>
|
||||||
|
<data num_results="1">
|
||||||
|
<METAR>
|
||||||
|
<raw_text>KOAK 260253Z 28014KT 10SM FEW010 FEW120 FEW180 12/08 A2999 RMK AO2 SLP155 T01220078 55002</raw_text>
|
||||||
|
<station_id>KOAK</station_id>
|
||||||
|
<observation_time>2022-03-26T02:53:00Z</observation_time>
|
||||||
|
<latitude>37.72</latitude>
|
||||||
|
<longitude>-122.23</longitude>
|
||||||
|
<temp_c>12.2</temp_c>
|
||||||
|
<dewpoint_c>7.8</dewpoint_c>
|
||||||
|
<wind_dir_degrees>280</wind_dir_degrees>
|
||||||
|
<wind_speed_kt>14</wind_speed_kt>
|
||||||
|
<visibility_statute_mi>10.0</visibility_statute_mi>
|
||||||
|
<altim_in_hg>29.991142</altim_in_hg>
|
||||||
|
<sea_level_pressure_mb>1015.5</sea_level_pressure_mb>
|
||||||
|
<quality_control_flags>
|
||||||
|
<auto_station>TRUE</auto_station>
|
||||||
|
</quality_control_flags>
|
||||||
|
<sky_condition cloud_base_ft_agl="1000" sky_cover="FEW" />
|
||||||
|
<sky_condition cloud_base_ft_agl="12000" sky_cover="FEW" />
|
||||||
|
<sky_condition cloud_base_ft_agl="18000" sky_cover="FEW" />
|
||||||
|
<flight_category>VFR</flight_category>
|
||||||
|
<three_hr_pressure_tendency_mb>-0.2</three_hr_pressure_tendency_mb>
|
||||||
|
<metar_type>METAR</metar_type>
|
||||||
|
<elevation_m>3.0</elevation_m>
|
||||||
|
</METAR>
|
||||||
|
</data>
|
||||||
|
</response>
|
||||||
Reference in New Issue
Block a user