More RadioID Compatibilty

Address the ever-changing formats and add resiliency for missing/incorrect data.
This commit is contained in:
Cort Buffington 2019-05-07 16:13:20 -05:00
parent c00e29386c
commit 94e4c4e69d
2 changed files with 48 additions and 29 deletions

View File

@ -94,10 +94,14 @@ def mk_id_dict(_path, _file):
_dict = {} _dict = {}
try: try:
with open(_path+_file, 'r', encoding='latin1') as _handle: with open(_path+_file, 'r', encoding='latin1') as _handle:
records = jload(_handle)['results'] records = jload(_handle)
records = records[[*records][0]]
_handle.close _handle.close
for record in records: for record in records:
_dict[int(record['id'])] = record['callsign'] try:
_dict[int(record['id'])] = record['callsign']
except:
pass
return _dict return _dict
except IOError: except IOError:
return _dict return _dict
@ -109,37 +113,47 @@ def mk_full_id_dict(_path, _file, _type):
_dict = {} _dict = {}
try: try:
with open(_path+_file, 'r', encoding='latin1') as _handle: with open(_path+_file, 'r', encoding='latin1') as _handle:
records = jload(_handle)['results'] records = jload(_handle)
records = records[[*records][0]]
_handle.close _handle.close
if _type == 'peer': if _type == 'peer':
for record in records: for record in records:
_dict[int(record['id'])] = { try:
'CALLSIGN': record['callsign'], _dict[int(record['id'])] = {
'CITY': record['city'], 'CALLSIGN': record['callsign'],
'STATE': record['state'], 'CITY': record['city'],
'COUNTRY': record['country'], 'STATE': record['state'],
'FREQ': record['frequency'], 'COUNTRY': record['country'],
'CC': record['color_code'], 'FREQ': record['frequency'],
'OFFSET': record['offset'], 'CC': record['color_code'],
'LINKED': record['ts_linked'], 'OFFSET': record['offset'],
'TRUSTEE': record['trustee'], 'LINKED': record['ts_linked'],
'NETWORK': record['ipsc_network'] 'TRUSTEE': record['trustee'],
} 'NETWORK': record['ipsc_network']
}
except:
pass
elif _type == 'subscriber': elif _type == 'subscriber':
for record in records: for record in records:
_dict[int(record['id'])] = { try:
'CALLSIGN': record['callsign'], _dict[int(record['id'])] = {
'NAME': (record['fname'] + ' ' + record['surname']), 'CALLSIGN': record['callsign'],
'CITY': record['city'], 'NAME': (record['fname'] + ' ' + record['surname']),
'STATE': record['state'], 'CITY': record['city'],
'COUNTRY': record['country'] 'STATE': record['state'],
} 'COUNTRY': record['country']
}
except:
pass
elif _type == 'tgid': elif _type == 'tgid':
for record in records: for record in records:
_dict[int(record['tgid'])] = { try:
'NAME': record['callsign'], _dict[int(record['tgid'])] = {
'ID': record['id'] 'NAME': record['callsign'],
} 'ID': record['id']
}
except:
pass
return _dict return _dict
except IOError: except IOError:
return _dict return _dict
@ -186,11 +200,16 @@ if __name__ == '__main__':
user file: ('callsign', 'city', 'country', 'fname', 'radio_id', 'remarks', 'state', 'surname') 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 # 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) print(result)
# Try updating subscriber aliases file # 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) print(result)
# Make Dictionaries # Make Dictionaries

View File

@ -7,7 +7,7 @@ def readme():
return file.read() return file.read()
setup(name='dmr_utils3', setup(name='dmr_utils3',
version='0.1.22', version='0.1.25',
description='ETSI DMR (Digital Mobile Radio) Tier II Utilities', 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', long_description='Modules to disassemble and assemble DMR packets, including generating and decoding various FEC routines',
classifiers=[ classifiers=[