Added New ID Alias Abilities
This commit is contained in:
parent
e908cdc7eb
commit
a06eda9ef0
|
@ -24,16 +24,24 @@ from os.path import isfile, getmtime
|
|||
from time import time
|
||||
from urllib import URLopener
|
||||
from csv import reader as csv_reader
|
||||
from csv import DictReader as csv_dict_reader
|
||||
from binascii import b2a_hex as ahex
|
||||
|
||||
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
||||
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||
__copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group'
|
||||
__copyright__ = 'Copyright (c) 2016-2017 Cortney T. Buffington, N0MJS and the K0USY Group'
|
||||
__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman'
|
||||
__license__ = 'GNU GPLv3'
|
||||
__maintainer__ = 'Cort Buffington, N0MJS'
|
||||
__email__ = 'n0mjs@me.com'
|
||||
|
||||
|
||||
# CONSTANTS
|
||||
SUB_FIELDS = ('ID', 'CALLSIGN', 'NAME', 'CITY', 'STATE', 'COUNTRY', 'TYPE')
|
||||
PEER_FIELDS = ('ID', 'CALLSIGN', 'CITY', 'STATE', 'COUNTRY', 'FREQ', 'CC', 'OFFSET', 'TYPE', 'LINKED', 'TRUSTEE', 'INFO', 'OTHER', 'NETWORK', )
|
||||
TGID_FIELDS = ('TGID', 'NAME')
|
||||
|
||||
|
||||
#************************************************
|
||||
# STRING UTILITY FUNCTIONS
|
||||
#************************************************
|
||||
|
@ -88,7 +96,8 @@ def try_download(_path, _file, _url, _stale,):
|
|||
result = 'ID ALIAS MAPPER: \'{}\' is current, not downloaded'.format(_file)
|
||||
url.close()
|
||||
return result
|
||||
|
||||
|
||||
# LEGACY VERSION - MAKES A SIMPLE {INTEGER ID: 'CALLSIGN'} DICTIONARY
|
||||
def mk_id_dict(_path, _file):
|
||||
dict = {}
|
||||
try:
|
||||
|
@ -100,65 +109,62 @@ def mk_id_dict(_path, _file):
|
|||
return dict
|
||||
except IOError:
|
||||
return dict
|
||||
|
||||
def mk_full_id_dict(_path, _file):
|
||||
|
||||
# NEW VERSION - MAKES A FULL DICTIONARY OF INFORMATION BASED ON TYPE OF ALIAS FILE
|
||||
# BASED ON DOWNLOADS FROM DMR-MARC, TGID IS STILL A "SIMPLE" DICTIONARY
|
||||
def mk_full_id_dict(_path, _file, _type):
|
||||
dict = {}
|
||||
if _type == 'subscriber':
|
||||
fields = SUB_FIELDS
|
||||
elif _type == 'peer':
|
||||
fields = PEER_FIELDS
|
||||
elif _type == 'tgid':
|
||||
fields = TGID_FIELDS
|
||||
try:
|
||||
with open(_path+_file, 'rU') as _handle:
|
||||
ids = csv_reader(_handle, dialect='excel', delimiter=',')
|
||||
ids = csv_dict_reader(_handle, fieldnames=fields, restkey='OTHER', dialect='excel', delimiter=',')
|
||||
for row in ids:
|
||||
print(repr(row[0]), repr(row[1]), row[3], row[4])
|
||||
dict[int(row[0])] = {'CALLSIGN': (row[1]), 'NAME': (row[2]), 'CITY': (row[3]), 'STATE': (row[4]), 'COUNTRY':(row[5])}
|
||||
for item in row:
|
||||
dict[int(row['ID'])] = row
|
||||
_handle.close
|
||||
return dict
|
||||
except IOError:
|
||||
return dict
|
||||
|
||||
# These are kept for legacy purposes; They only return a callsign
|
||||
def get_info(_id, _dict):
|
||||
if _id in _dict:
|
||||
return _dict[_id]
|
||||
return _id
|
||||
|
||||
def get_alias(_id, _dict):
|
||||
_int_id = int_id(_id)
|
||||
if _int_id in _dict:
|
||||
return _dict[_int_id]
|
||||
return _int_id
|
||||
|
||||
# These do not work yet, don't use them.
|
||||
def get_callsign(_id, _dict):
|
||||
if type(_id) != int:
|
||||
# THESE ARE THE SAME THING FOR LEGACY PURPOSES
|
||||
def get_alias(_id, _dict, *args):
|
||||
if type(_id) == str:
|
||||
_id = int_id(_id)
|
||||
if _id in _dict:
|
||||
return _dict[_id]['CALLSIGN']
|
||||
return _id
|
||||
|
||||
def get_name(_id, _dict):
|
||||
if type(_id) != int:
|
||||
_id = int_id(_id)
|
||||
if _id in _dict:
|
||||
return _dict[_id]['NAME']
|
||||
return _id
|
||||
|
||||
def get_call_name(_id, _dict):
|
||||
if type(_id) != int:
|
||||
_id = int_id(_id)
|
||||
if _id in _dict:
|
||||
return _dict[_id]['CALLSIGN'] + ', ' + _dict[_id]['NAME']
|
||||
return _id
|
||||
|
||||
def get_alias_list(_id, _dict, *args):
|
||||
if type(_id) != int:
|
||||
_id = int_id(_id)
|
||||
retValue = [_id,]
|
||||
if _id in _dict:
|
||||
if args:
|
||||
retValue = []
|
||||
for _item in args:
|
||||
retValue.append(_dict[_id][_item])
|
||||
try:
|
||||
retValue.append(_dict[_id][_item])
|
||||
except TypeError:
|
||||
return _dict[_id]
|
||||
return retValue
|
||||
else:
|
||||
retValue = retValue + [_dict[_id]['CALLSIGN'], _dict[_id]['NAME'], _dict[_id]['CITY'], _dict[_id]['STATE'], _dict[_id]['COUNTRY']]
|
||||
return retValue
|
||||
return retValue
|
||||
return _dict[_id]
|
||||
return _id
|
||||
|
||||
def get_info(_id, _dict, *args):
|
||||
if type(_id) == str:
|
||||
_id = int_id(_id)
|
||||
if _id in _dict:
|
||||
if args:
|
||||
retValue = []
|
||||
for _item in args:
|
||||
try:
|
||||
retValue.append(_dict[_id][_item])
|
||||
except TypeError:
|
||||
return _dict[_id]
|
||||
return retValue
|
||||
else:
|
||||
return _dict[_id]
|
||||
return _id
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ def readme():
|
|||
return file.read()
|
||||
|
||||
setup(name='dmr_utils',
|
||||
version='0.1.5',
|
||||
version='0.1.6',
|
||||
description='ETSI DMR (Digital Mobile Radio) Teir II Utilities',
|
||||
long_description='Modules to disassemble and assemble DMR packets, including generating and decoding varoius FEC routines',
|
||||
classifiers=[
|
||||
|
|
Loading…
Reference in New Issue