More RadioID compatibilty

Fixing this to agree with the ever changing formats over at RadioID and to be more tolerant of missing data.
This commit is contained in:
Cort Buffington 2019-05-07 16:11:56 -05:00
parent c1b7edfcc4
commit 66a082dbb8
2 changed files with 47 additions and 28 deletions

View File

@ -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:
try:
_dict[int(record['id'])] = record['callsign'].encode('ascii','ignore')
except:
pass
return _dict
except IOError:
return _dict
@ -115,10 +119,12 @@ 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:
try:
_dict[int(record['id'])] = {
'CALLSIGN': record['callsign'],
'CITY': record['city'],
@ -131,8 +137,11 @@ def mk_full_id_dict(_path, _file, _type):
'TRUSTEE': record['trustee'],
'NETWORK': record['ipsc_network']
}
except:
pass
elif _type == 'subscriber':
for record in records:
try:
_dict[int(record['id'])] = {
'CALLSIGN': record['callsign'],
'NAME': (record['fname'] + ' ' + record['surname']),
@ -140,11 +149,16 @@ def mk_full_id_dict(_path, _file, _type):
'STATE': record['state'],
'COUNTRY': record['country']
}
except:
pass
elif _type == 'tgid':
for record in records:
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

View File

@ -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=[