ADD Rufzeichenliste for testing purposes

This commit is contained in:
Thomas Kuschel 2024-06-23 19:49:35 +02:00
parent 545f4db35f
commit 3a8032b787
2 changed files with 43 additions and 20 deletions

BIN
afu/Rufzeichenliste_AT_Stand_20240601.pdf (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -23,15 +23,34 @@ def call_description():
def call_configparser(): def call_configparser():
config = configparser.ConfigParser() config = configparser.ConfigParser()
config['MARIADB'] = { try:
'db_user': 'om', configfile = get_active_path('config.ini')
'db_password': 'oe3tkt', ret = config.read(configfile)
'db_host': '127.0.0.1', if not ret:
'db_port': 3306, print(f'The file {configfile} was not found. We create a new config file.')
'db_database': 'callbook' 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: with open(get_active_path('config.ini'), 'w') as configfile:
config.write(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(): def call_parser():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@ -54,12 +73,8 @@ def call_parser():
opt = parser.parse_args() opt = parser.parse_args()
opt.verbose = 0 if opt.verbose is None else sum(opt.verbose) 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) == '': 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 return opt
def call_website(url,verbose,path='',interactive=False,output='',mariadb=''): 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 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) return os.path.join(os.path.dirname(os.path.abspath(__file__)), file)
def get_gender(firstnames, surname, call, verbose=0): def get_gender(firstnames, surname, call, verbose=0):
@ -450,20 +465,25 @@ if __name__ == '__main__':
sys.exit(1) sys.exit(1)
try: try:
configdb = config['MariaDB'] # fetch from config file, then do with fallbacks:
conn = mariadb.connect( conn = mariadb.connect(
user = 'om', user = configdb.get('user', 'om'),
password = 'oe3tkt', password = configdb.get('password','oe3tkt'),
host='127.0.0.1', host = configdb.get('host','127.0.0.1'),
port=3306, port = configdb.getint('port',3306),
database='callbook' database = configdb.get('database','callbook')
) )
except mariadb.Error as e: except mariadb.Error as e:
print(f'Error connectiong to MariaDB platform: {e}') print(f'Error connectiong to MariaDB platform: {e}')
sys.exit(5) sys.exit(5)
print(f'Connected to MariaDB API Version {mariadb.mariadbapi_version}.')
print(datetime.datetime.now(datetime.UTC)) print(datetime.datetime.now(datetime.UTC))
# Get Cursor # Get Cursor
cur = conn.cursor() cur = conn.cursor()
cur.execute('SELECT VERSION()')
print(cur.fetchone()[0])
sql_file = '.sql_init' sql_file = '.sql_init'
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), sql_file) path = os.path.join(os.path.dirname(os.path.abspath(__file__)), sql_file)
exec_sql_file(cur, path) exec_sql_file(cur, path)