From 3a8032b7875718177dc92c76965d908dff5f9131 Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Sun, 23 Jun 2024 19:49:35 +0200 Subject: [PATCH] ADD Rufzeichenliste for testing purposes --- afu/Rufzeichenliste_AT_Stand_20240601.pdf | 3 ++ afu/callbook.py | 60 +++++++++++++++-------- 2 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 afu/Rufzeichenliste_AT_Stand_20240601.pdf diff --git a/afu/Rufzeichenliste_AT_Stand_20240601.pdf b/afu/Rufzeichenliste_AT_Stand_20240601.pdf new file mode 100644 index 0000000..a8d195e --- /dev/null +++ b/afu/Rufzeichenliste_AT_Stand_20240601.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3940ccf3799c50e4dc3325f48d5d03ea27e3f298d5def012cdb49b54e120ccb +size 1878785 diff --git a/afu/callbook.py b/afu/callbook.py index 621cd50..99c4cdb 100755 --- a/afu/callbook.py +++ b/afu/callbook.py @@ -23,15 +23,34 @@ def call_description(): def call_configparser(): config = configparser.ConfigParser() - config['MARIADB'] = { - 'db_user': 'om', - 'db_password': 'oe3tkt', - 'db_host': '127.0.0.1', - 'db_port': 3306, - 'db_database': 'callbook' - } - with open(get_active_path('config.ini'), 'w') as configfile: - config.write(configfile) + try: + configfile = get_active_path('config.ini') + ret = config.read(configfile) + if not ret: + print(f'The file {configfile} was not found. We create a new config file.') + config['Common']={ + 'description': 'Download and Parse the Austrian Callbook', + 'author': 'Thomas Kuschel, OE3TKT (OExTKT)', + 'version': __version__, + 'created': datetime.datetime.now() + } + config['MariaDB'] = { + 'user': 'om', + 'password': 'oe3tkt', + 'host': '127.0.0.1', + 'port': 3306, + 'database': 'callbook'} + with open(get_active_path('config.ini'), 'w') as configfile: + config.write(configfile, False) + print(f'Configuration file "config.ini" created.') + + except FileNotFoundError: + sys.exit(8) + except Exception as e: + print('Error: {}'.format(e), file=sys.stderr) + sys.exit(9) + # print(config.sections()) ## ['Common', 'MariaDB'] + return config def call_parser(): parser = argparse.ArgumentParser( @@ -54,12 +73,8 @@ def call_parser(): opt = parser.parse_args() opt.verbose = 0 if opt.verbose is None else sum(opt.verbose) - ask = opt.path != '' - base = os.path.basename(opt.path) - dir = os.path.dirname(opt.path) if opt.path != '' and os.path.dirname(opt.path) == '': - opt.path = os.path.join(os.path.dirname(os.path.abspath(__file__)), opt.path) - + opt.path = get_active_path(opt.path) return opt def call_website(url,verbose,path='',interactive=False,output='',mariadb=''): @@ -168,7 +183,7 @@ def gender_substring(path, search_substring, verbose=0): gender_substring.lines = None -def get_active_path(file) +def get_active_path(file): return os.path.join(os.path.dirname(os.path.abspath(__file__)), file) def get_gender(firstnames, surname, call, verbose=0): @@ -450,20 +465,25 @@ if __name__ == '__main__': sys.exit(1) try: + configdb = config['MariaDB'] # fetch from config file, then do with fallbacks: conn = mariadb.connect( - user = 'om', - password = 'oe3tkt', - host='127.0.0.1', - port=3306, - database='callbook' + user = configdb.get('user', 'om'), + password = configdb.get('password','oe3tkt'), + host = configdb.get('host','127.0.0.1'), + port = configdb.getint('port',3306), + database = configdb.get('database','callbook') ) except mariadb.Error as e: print(f'Error connectiong to MariaDB platform: {e}') sys.exit(5) + print(f'Connected to MariaDB API Version {mariadb.mariadbapi_version}.') print(datetime.datetime.now(datetime.UTC)) # Get Cursor cur = conn.cursor() + cur.execute('SELECT VERSION()') + print(cur.fetchone()[0]) + sql_file = '.sql_init' path = os.path.join(os.path.dirname(os.path.abspath(__file__)), sql_file) exec_sql_file(cur, path)