Merge branch 'master' of ssh://kuschel.at:21861/public/scripts

This commit is contained in:
Thomas Kuschel 2024-06-23 15:24:03 +02:00
commit 73a989e4a4
2 changed files with 28 additions and 4 deletions

View File

@ -1,5 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = '1.0.0'
__website__ = 'https://www.fb.gv.at/Funk/amateurfunkdienst.html'
import argparse import argparse
import os import os
import mariadb import mariadb
@ -9,9 +12,7 @@ import pypdf
from pypdf import PdfReader from pypdf import PdfReader
import re # regular expression import re # regular expression
import datetime import datetime
import configparser
__version__ = '1.0.0'
__website__ = 'https://www.fb.gv.at/Funk/amateurfunkdienst.html'
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
@ -20,6 +21,18 @@ from selenium.webdriver.chrome.service import Service as ChromiumService
def call_description(): def call_description():
print(f'Download and Parse the Austrian Callbook Version {__version__}') 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(): def call_parser():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Download and Parse the Austrian Callbook', description='Download and Parse the Austrian Callbook',
@ -155,12 +168,15 @@ def gender_substring(path, search_substring, verbose=0):
gender_substring.lines = None 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): def get_gender(firstnames, surname, call, verbose=0):
# load the .gender file: # load the .gender file:
genderfile = '.gender' genderfile = '.gender'
gender = 'x' gender = 'x'
gpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), genderfile) gpath = get_active_path(genderfile)
if os.path.exists(gpath): if os.path.exists(gpath):
firstname = firstnames.split(' ', 1)[0] 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 gender = gender_substring(gpath, firstname, verbose=0) # only check 1st/firstname of name, important when there are more than 1 firstnames
@ -423,6 +439,7 @@ def exec_sql_file(cursor, sql_file):
if __name__ == '__main__': if __name__ == '__main__':
args = call_parser() args = call_parser()
config = call_configparser()
try: try:
filename = call_website(**vars(args)) filename = call_website(**vars(args))
if args.verbose > 1: if args.verbose > 1:

7
config.ini Normal file
View File

@ -0,0 +1,7 @@
[MARIADB]
db_user = om
db_password = oe3tkt
db_host = 127.0.0.1
db_port = 3306
db_database = callbook