Initial commit
This commit is contained in:
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()
|
||||
|
||||
Reference in New Issue
Block a user