diff --git a/.github/actions/py3-tox/action.yaml b/.github/actions/py3-tox/action.yaml index e7c35303..edc629ff 100644 --- a/.github/actions/py3-tox/action.yaml +++ b/.github/actions/py3-tox/action.yaml @@ -8,6 +8,9 @@ inputs: required: false type: string default: '3' + tox_args: + required: false + type: string runs: using: "composite" @@ -22,4 +25,4 @@ runs: shell: bash run: | git fetch origin $GITHUB_BASE_REF || true - tox -e ${{ inputs.tox_target }} + tox -e ${{ inputs.tox_target }} -- ${{ inputs.tox_args }} diff --git a/.github/workflows/py3-test.yaml b/.github/workflows/py3-test.yaml index ebbab9af..2b2abf77 100644 --- a/.github/workflows/py3-test.yaml +++ b/.github/workflows/py3-test.yaml @@ -23,6 +23,7 @@ jobs: uses: ./.github/actions/py3-tox with: tox_target: unit + tox_args: -k "not network" - name: Archive results uses: actions/upload-artifact@v4 with: diff --git a/chirp/sources/repeaterbook.py b/chirp/sources/repeaterbook.py index 1bf00aa6..bc959e41 100644 --- a/chirp/sources/repeaterbook.py +++ b/chirp/sources/repeaterbook.py @@ -2,6 +2,7 @@ import datetime import glob import json import logging +import lzma import math import os @@ -115,18 +116,8 @@ class RepeaterBook(base.NetworkResultRadio): LOG.debug('RepeaterBook database %s too old: %s', fn, modified_dt) - params = {'country': country, - 'stype': service} - if country in NA_COUNTRIES: - export = 'export.php' - else: - export = 'exportROW.php' - if country in STATES: - params['state'] = state - - r = requests.get('https://www.repeaterbook.com/api/%s' % export, + r = requests.get('https://data.chirpmyradio.com/rb/%s.xz' % fn, headers=base.HEADERS, - params=params, stream=True) if r.status_code != 200: if modified: @@ -141,8 +132,10 @@ class RepeaterBook(base.NetworkResultRadio): probable_end = 3 << 20 counter = 0 data = b'' + decomp = lzma.LZMADecompressor(format=lzma.FORMAT_XZ) with open(tmp, 'wb') as f: for chunk in r.iter_content(chunk_size=chunk_size): + chunk = decomp.decompress(chunk) f.write(chunk) data += chunk counter += len(chunk) diff --git a/tests/unit/test_repeaterbook.py b/tests/unit/test_repeaterbook.py index 57532fa7..2cef5e77 100644 --- a/tests/unit/test_repeaterbook.py +++ b/tests/unit/test_repeaterbook.py @@ -1,5 +1,6 @@ import datetime import json +import lzma import os import shutil import tempfile @@ -184,11 +185,13 @@ class TestRepeaterbook(unittest.TestCase): status.send_fail.assert_called() def test_get_data_no_results(self): + comp = lzma.LZMACompressor(format=lzma.FORMAT_XZ) + fake_data = comp.compress(json.dumps({'count': 0}).encode()) + fake_data += comp.flush() rb = repeaterbook.RepeaterBook() with mock.patch('requests.get') as mock_get: mock_get.return_value.status_code = 200 - mock_get.return_value.iter_content.return_value = [json.dumps( - {'count': 0}).encode()] + mock_get.return_value.iter_content.return_value = [fake_data] status = mock.MagicMock() r = rb.get_data(status, 'US', 'OR', '') self.assertIsNone(r) @@ -202,11 +205,13 @@ class TestRepeaterbook(unittest.TestCase): files = os.listdir(self.tempdir) # Make sure we started with no data files self.assertEqual(0, len(files)) + comp = lzma.LZMACompressor(format=lzma.FORMAT_XZ) + fake_data = comp.compress(json.dumps({'count': 1}).encode()) + fake_data += comp.flush() rb = repeaterbook.RepeaterBook() with mock.patch('requests.get') as mock_get: mock_get.return_value.status_code = 200 - mock_get.return_value.iter_content.return_value = [json.dumps( - {'count': 1}).encode()] + mock_get.return_value.iter_content.return_value = [fake_data] status = mock.MagicMock() r = rb.get_data(status, 'US', 'OR', '') self.assertIsNotNone(r)