scripts/afu/callbook.py

72 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import sys
import time
__version__ = '1.0.0'
__website__ = 'https://www.fb.gv.at/Funk/amateurfunkdienst.html'
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromiumService
def call_description():
print(f'Download and Parse the Austrian Callbook Version {__version__}')
def call_parser():
parser = argparse.ArgumentParser(
description='Download and Parse the Austrian Callbook',
epilog=f'''
Written by Thomas Kuschel,
Version {__version__}
'''
)
parser.add_argument('--interactive', '-i', action='store_true', default=False)
# parser.add_argument('--server', '-s', default=__website__, required=False)
parser.add_argument('--version', '-v', action='version', version='{} {}'.format(os.path.split(__file__)[1],__version__))
parser.add_argument('url', metavar='URL', nargs='?', default=__website__)
return parser.parse_args()
def call_website(url,interactive=False):
if(interactive):
print('Interactive')
driver=webdriver.Chrome()
else:
print('Headless Script')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
driver.get(url)
print(driver.title)
elements = driver.find_elements(By.XPATH,'//a[contains(@href,"Rufzeichen")]')
if elements:
element = elements[0]
filename = element.click()
else:
print('Sorry, no Link containing "Rufzeichen" found.')
driver.close()
sys.exit(2)
print(element.text)
print()
time.sleep(5)
driver.close()
if __name__ == '__main__':
# call_description()
args = call_parser()
try:
filename = call_website(**vars(args))
sys.exit(0)
except Exception as e:
print('Error: {}'.format(e), file=sys.stderr)
sys.exit(1)