From 66a082dbb836be9c27695b8311872c893b7e916c Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Tue, 7 May 2019 16:11:56 -0500 Subject: [PATCH] More RadioID compatibilty Fixing this to agree with the ever changing formats over at RadioID and to be more tolerant of missing data. --- dmr_utils/utils.py | 73 +++++++++++++++++++++++++++++----------------- setup.py | 2 +- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/dmr_utils/utils.py b/dmr_utils/utils.py index 9ee9e77..7152279 100755 --- a/dmr_utils/utils.py +++ b/dmr_utils/utils.py @@ -101,10 +101,14 @@ def mk_id_dict(_path, _file): _dict = {} try: with open(_path+_file, 'rU') as _handle: - records = jload(_handle)['results'] + records = jload(_handle) + records = records[records.keys()[0]] _handle.close for record in records: - _dict[int(record['id'])] = record['callsign'].encode('ascii','ignore') + try: + _dict[int(record['id'])] = record['callsign'].encode('ascii','ignore') + except: + pass return _dict except IOError: return _dict @@ -115,36 +119,46 @@ def mk_full_id_dict(_path, _file, _type): _dict = {} try: with open(_path+_file, 'rU') as _handle: - records = jload(_handle)['results'] + records = jload(_handle) + records = records[records.keys()[0]] _handle.close if _type == 'peer': for record in records: - _dict[int(record['id'])] = { - 'CALLSIGN': record['callsign'], - 'CITY': record['city'], - 'STATE': record['state'], - 'COUNTRY': record['country'], - 'FREQ': record['frequency'], - 'CC': record['color_code'], - 'OFFSET': record['offset'], - 'LINKED': record['ts_linked'], - 'TRUSTEE': record['trustee'], - 'NETWORK': record['ipsc_network'] - } + try: + _dict[int(record['id'])] = { + 'CALLSIGN': record['callsign'], + 'CITY': record['city'], + 'STATE': record['state'], + 'COUNTRY': record['country'], + 'FREQ': record['frequency'], + 'CC': record['color_code'], + 'OFFSET': record['offset'], + 'LINKED': record['ts_linked'], + 'TRUSTEE': record['trustee'], + 'NETWORK': record['ipsc_network'] + } + except: + pass elif _type == 'subscriber': for record in records: - _dict[int(record['id'])] = { - 'CALLSIGN': record['callsign'], - 'NAME': (record['fname'] + ' ' + record['surname']), - 'CITY': record['city'], - 'STATE': record['state'], - 'COUNTRY': record['country'] - } + try: + _dict[int(record['id'])] = { + 'CALLSIGN': record['callsign'], + 'NAME': (record['fname'] + ' ' + record['surname']), + 'CITY': record['city'], + 'STATE': record['state'], + 'COUNTRY': record['country'] + } + except: + pass elif _type == 'tgid': for record in records: - _dict[int(record['id'])] = { - 'NAME': record['callsign'] - } + try: + _dict[int(record['id'])] = { + 'NAME': record['callsign'] + } + except: + pass return _dict except IOError: return _dict @@ -191,12 +205,17 @@ if __name__ == '__main__': user file: ('callsign', 'city', 'country', 'fname', 'radio_id', 'remarks', 'state', 'surname') ''' + #PEER_URL = 'https://www.radioid.net/api/dmr/repeater/?country=united%20states' + #SUBSCRIBER_URL = 'https://www.radioid.net/api/dmr/user/?country=united%20states' + PEER_URL = 'https://www.radioid.net/static/rptrs.json' + SUBSCRIBER_URL = 'https://www.radioid.net/static/users.json' + # Try updating peer aliases file - result = try_download('/tmp/', 'peers.json', 'https://www.radioid.net/api/dmr/repeater/?country=united%20states', 0) + result = try_download('/tmp/', 'peers.json', PEER_URL, 0) print(result) # Try updating subscriber aliases file - result = try_download('/tmp/', 'subscribers.json', 'https://www.radioid.net/api/dmr/user/?country=united%20states', 0) + result = try_download('/tmp/', 'subscribers.json', SUBSCRIBER_URL, 0) print(result) # Make Dictionaries diff --git a/setup.py b/setup.py index 698977e..76a63ca 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ def readme(): return file.read() setup(name='dmr_utils', - version='0.1.24', + version='0.1.25', description='ETSI DMR (Digital Mobile Radio) Tier II Utilities', long_description='Modules to disassemble and assemble DMR packets, including generating and decoding various FEC routines', classifiers=[