From 763826953a9d61ccd1da4247521a8dc9b7656bb5 Mon Sep 17 00:00:00 2001 From: "Fabian P. Schmidt" Date: Fri, 25 Mar 2016 19:59:36 +0100 Subject: [PATCH] Add submodule ddb --- CHANGELOG.md | 1 + ogn/ddb/__init__.py | 1 + ogn/ddb/utils.py | 11 +++++++++++ tests/ddb/__init__.py | 0 tests/ddb/test_utils.py | 10 ++++++++++ 5 files changed, 23 insertions(+) create mode 100644 ogn/ddb/__init__.py create mode 100644 ogn/ddb/utils.py create mode 100644 tests/ddb/__init__.py create mode 100644 tests/ddb/test_utils.py diff --git a/CHANGELOG.md b/CHANGELOG.md index bfc1a33..ae03622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased - aprs client: Added the possibility of a timed callback +- Added ogn.ddb submodule which provides the generator `get_ddb_devices` ## 0.3.0 - 2016-03-18 The repository ogn-python splitted up into two separate repositories: diff --git a/ogn/ddb/__init__.py b/ogn/ddb/__init__.py new file mode 100644 index 0000000..e96fbbd --- /dev/null +++ b/ogn/ddb/__init__.py @@ -0,0 +1 @@ +from ogn.ddb.utils import get_ddb_devices # flake8: noqa diff --git a/ogn/ddb/utils.py b/ogn/ddb/utils.py new file mode 100644 index 0000000..5fef177 --- /dev/null +++ b/ogn/ddb/utils.py @@ -0,0 +1,11 @@ +import requests + +DDB_URL = "http://ddb.glidernet.org/download/?j=1" + + +def get_ddb_devices(): + r = requests.get(DDB_URL) + for device in r.json()['devices']: + device.update({'identified': device['identified'] == 'Y', + 'tracked': device['tracked'] == 'Y'}) + yield device diff --git a/tests/ddb/__init__.py b/tests/ddb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/ddb/test_utils.py b/tests/ddb/test_utils.py new file mode 100644 index 0000000..73c9e35 --- /dev/null +++ b/tests/ddb/test_utils.py @@ -0,0 +1,10 @@ +import unittest + +from ogn.ddb import get_ddb_devices + + +class TestStringMethods(unittest.TestCase): + def test_get_ddb_devices(self): + devices = list(get_ddb_devices()) + self.assertGreater(len(devices), 4000) + self.assertCountEqual(devices[0].keys(), ['device_type', 'device_id', 'aircraft_model', 'registration', 'cn', 'tracked', 'identified'])