|
|
|
@@ -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)
|
|
|
|
|