Uh oh!
There was an error while loading. Please reload this page.
forked from Meisterschueler/ogn-python
- Notifications
You must be signed in to change notification settings - Fork 4
Examples
Fabian P. Schmidt edited this page Mar 30, 2016
·
6 revisions
The gateway of ogn-python stores all beacons to a database and your program connects to this database. If you want to process the incoming beacons before they hit any database, use python-ogn-client directly.
Before you can execute the following example, you have to
- install dependencies and create the database (installation and setup) and
- receive some beacons (running the aprs client).
This example connects with the default database from ogn-python and shows the sum of received messages per receiver in the last hour.
fromdatetimeimportdatetime, timedeltafromsqlalchemyimportfuncfromogn.modelimportAircraftBeaconfromogn.commands.dbutilsimportsessiondefshow_last_hour():
query=session.query(AircraftBeacon.receiver_name, func.count(AircraftBeacon.id)) \
.filter(AircraftBeacon.timestamp> (datetime.utcnow() -timedelta(hours=1))) \
.group_by(AircraftBeacon.receiver_name) \
.order_by(AircraftBeacon.receiver_name)
for [receiver_name, message_count] inquery.all():
print("{0:9s}: {1:5d}".format(receiver_name, message_count))
if__name__=='__main__':
show_last_hour()