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 time import time
|
||||||
from urllib import URLopener
|
from urllib import URLopener
|
||||||
from csv import reader as csv_reader
|
from csv import reader as csv_reader
|
||||||
|
from csv import DictReader as csv_dict_reader
|
||||||
from binascii import b2a_hex as ahex
|
from binascii import b2a_hex as ahex
|
||||||
|
|
||||||
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
||||||
__author__ = 'Cortney T. Buffington, N0MJS'
|
__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'
|
__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman'
|
||||||
__license__ = 'GNU GPLv3'
|
__license__ = 'GNU GPLv3'
|
||||||
__maintainer__ = 'Cort Buffington, N0MJS'
|
__maintainer__ = 'Cort Buffington, N0MJS'
|
||||||
__email__ = 'n0mjs@me.com'
|
__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
|
# STRING UTILITY FUNCTIONS
|
||||||
#************************************************
|
#************************************************
|
||||||
@ -89,6 +97,7 @@ def try_download(_path, _file, _url, _stale,):
|
|||||||
url.close()
|
url.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
# LEGACY VERSION - MAKES A SIMPLE {INTEGER ID: 'CALLSIGN'} DICTIONARY
|
||||||
def mk_id_dict(_path, _file):
|
def mk_id_dict(_path, _file):
|
||||||
dict = {}
|
dict = {}
|
||||||
try:
|
try:
|
||||||
@ -101,64 +110,61 @@ def mk_id_dict(_path, _file):
|
|||||||
except IOError:
|
except IOError:
|
||||||
return dict
|
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 = {}
|
dict = {}
|
||||||
|
if _type == 'subscriber':
|
||||||
|
fields = SUB_FIELDS
|
||||||
|
elif _type == 'peer':
|
||||||
|
fields = PEER_FIELDS
|
||||||
|
elif _type == 'tgid':
|
||||||
|
fields = TGID_FIELDS
|
||||||
try:
|
try:
|
||||||
with open(_path+_file, 'rU') as _handle:
|
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:
|
for row in ids:
|
||||||
print(repr(row[0]), repr(row[1]), row[3], row[4])
|
for item in row:
|
||||||
dict[int(row[0])] = {'CALLSIGN': (row[1]), 'NAME': (row[2]), 'CITY': (row[3]), 'STATE': (row[4]), 'COUNTRY':(row[5])}
|
dict[int(row['ID'])] = row
|
||||||
_handle.close
|
_handle.close
|
||||||
return dict
|
return dict
|
||||||
except IOError:
|
except IOError:
|
||||||
return dict
|
return dict
|
||||||
|
|
||||||
# These are kept for legacy purposes; They only return a callsign
|
# THESE ARE THE SAME THING FOR LEGACY PURPOSES
|
||||||
def get_info(_id, _dict):
|
def get_alias(_id, _dict, *args):
|
||||||
|
if type(_id) == str:
|
||||||
|
_id = int_id(_id)
|
||||||
if _id in _dict:
|
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 _dict[_id]
|
||||||
return _id
|
return _id
|
||||||
|
|
||||||
def get_alias(_id, _dict):
|
def get_info(_id, _dict, *args):
|
||||||
_int_id = int_id(_id)
|
if type(_id) == str:
|
||||||
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:
|
|
||||||
_id = int_id(_id)
|
_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 _id in _dict:
|
||||||
if args:
|
if args:
|
||||||
|
retValue = []
|
||||||
for _item in args:
|
for _item in args:
|
||||||
|
try:
|
||||||
retValue.append(_dict[_id][_item])
|
retValue.append(_dict[_id][_item])
|
||||||
|
except TypeError:
|
||||||
|
return _dict[_id]
|
||||||
|
return retValue
|
||||||
else:
|
else:
|
||||||
retValue = retValue + [_dict[_id]['CALLSIGN'], _dict[_id]['NAME'], _dict[_id]['CITY'], _dict[_id]['STATE'], _dict[_id]['COUNTRY']]
|
return _dict[_id]
|
||||||
return retValue
|
return _id
|
||||||
return retValue
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ def readme():
|
|||||||
return file.read()
|
return file.read()
|
||||||
|
|
||||||
setup(name='dmr_utils',
|
setup(name='dmr_utils',
|
||||||
version='0.1.5',
|
version='0.1.6',
|
||||||
description='ETSI DMR (Digital Mobile Radio) Teir II Utilities',
|
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',
|
long_description='Modules to disassemble and assemble DMR packets, including generating and decoding varoius FEC routines',
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user