From 234a8962786fa07f6f10e21cc6f22d4d8dc936c4 Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Sun, 23 Jun 2024 15:21:15 +0200 Subject: [PATCH] ADD config.ini and parser --- afu/callbook.py | 25 +++++++++++++++++++++---- config.ini | 7 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 config.ini diff --git a/afu/callbook.py b/afu/callbook.py index 27316c2..3a0e6e1 100755 --- a/afu/callbook.py +++ b/afu/callbook.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +__version__ = '1.0.0' +__website__ = 'https://www.fb.gv.at/Funk/amateurfunkdienst.html' + import argparse import os import mariadb @@ -9,9 +12,7 @@ import pypdf from pypdf import PdfReader import re # regular expression import datetime - -__version__ = '1.0.0' -__website__ = 'https://www.fb.gv.at/Funk/amateurfunkdienst.html' +import configparser from selenium import webdriver from selenium.webdriver.common.by import By @@ -20,6 +21,18 @@ from selenium.webdriver.chrome.service import Service as ChromiumService def call_description(): print(f'Download and Parse the Austrian Callbook Version {__version__}') +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) + def call_parser(): parser = argparse.ArgumentParser( description='Download and Parse the Austrian Callbook', @@ -149,12 +162,15 @@ def gender_substring(path, search_substring, verbose=0): gender_substring.lines = None +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): # load the .gender file: genderfile = '.gender' gender = 'x' - gpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), genderfile) + gpath = get_active_path(genderfile) if os.path.exists(gpath): firstname = firstnames.split(' ', 1)[0] gender = gender_substring(gpath, firstname, verbose=0) # only check 1st/firstname of name, important when there are more than 1 firstnames @@ -417,6 +433,7 @@ def exec_sql_file(cursor, sql_file): if __name__ == '__main__': args = call_parser() + config = call_configparser() try: filename = call_website(**vars(args)) if args.verbose > 1: diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..16b2650 --- /dev/null +++ b/config.ini @@ -0,0 +1,7 @@ +[MARIADB] +db_user = om +db_password = oe3tkt +db_host = 127.0.0.1 +db_port = 3306 +db_database = callbook +