# ZLcontact.py, DJ9ZL, 30-Jun-2019 # Version 9-Jun-2021 # Reformat DMR digital contact list for AT-D868UV V1.33 # https://dj9zl.darc.de import win32com.client import ctypes import sys import configparser #import os MB_OK = 0x0 MB_OKCXL = 0x01 MB_YESNOCXL = 0x03 MB_YESNO = 0x04 MB_HELP = 0x4000 ICON_EXCLAIM = 0x30 ICON_INFO = 0x40 ICON_STOP = 0x10 progname = 'ZLcontact' infile = 'DigitalContactList.csv' outfile = 'ZLcontacts.csv' def Mbox(title, text, style): return ctypes.windll.user32.MessageBoxW(None, text, title, style); def HK(str): return chr(34)+str+chr(34)+','; try: config = configparser.ConfigParser() config.read('ZLcontact.ini') countryselect = config['DEFAULT']['countryselect'] print(countryselect) if countryselect: countrylist = config['DEFAULT']['countrylist'] yesno = int(Mbox(progname, 'The contact list contains the following countries:\n' +countrylist +'\n\nContinue?', MB_YESNO | ICON_INFO)) if yesno == 7: Mbox(progname, '*** Cancelled! ***', MB_OK | ICON_INFO) sys.exit() except: Mbox(progname, 'Can\'t parse ZLcontact.ini', MB_OK | ICON_INFO) sys.exit() #=============================================================== try: oShell = win32com.client.Dispatch('Wscript.Shell') strDesktop = oShell.SpecialFolders('Desktop') except: Mbox(progname, 'Can\'t create Wscript.Shell', MB_OK | ICON_INFO) sys.exit() infile = strDesktop+'\\'+infile try: o_infile = open(infile, 'r', encoding='utf-8') except IOError: Mbox(progname, 'Can\'t open input file ' +infile, MB_OK | ICON_INFO) sys.exit() #------------------------------------------------------------------------------ outfile = strDesktop+'\\'+outfile try: o_outfile = open(outfile, 'w+') except IOError: Mbox(progname, 'Can\'t create/write output file ' +outfile, MB_OK | ICON_INFO) sys.exit() try: line = o_infile.readline() header = HK('No.') +HK('Radio ID') +HK('Callsign') +HK('Name') \ +HK('City') +HK('State') +HK('Country') +HK('Remarks') +HK('Call Type') +chr(34) +'Call Alert' +chr(34) +'\n' o_outfile.write(header) except (IOError): Mbox(progname, 'Error in reading/writing header line', MB_OK | ICON_INFO) sys.exit() no = 0 skipped = 0 while True: try: line = str(o_infile.readline()) if not line: break inarray = line.split(',') str6 = inarray[6] p = str6.rfind(' ') state = str6[1:p] country = str6[p+1:len(str6)-1] if country in countrylist: no = no + 1 radioid = inarray[1] callsign = inarray[3] name = inarray[4] city = inarray[5] remarks = inarray[7] calltype = inarray[8] callalert = inarray[9] outline = str(no)+chr(34)+','+radioid+','+chr(34)+chr(34)+','+callsign+','+city+','+chr(34)+state+chr(34) \ +','+chr(34)+country+chr(34)+','+remarks+','+calltype+','+callalert+chr(34) o_outfile.write(outline) except: skipped = skipped + 1 pass #------------------------------------------------------------------------------ o_infile.close() o_outfile.close() Mbox(progname, '*** '+str(no) +' contacts written ***\t' \ +str(skipped) +' records skipped\n' +'Output file is ' +outfile, MB_OK | ICON_INFO) sys.exit()