ADD callbook.py init release 1.0.0
This commit is contained in:
parent
99912ce78c
commit
656ed78288
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.vscode
|
||||
*.pdf
|
@ -60,7 +60,7 @@ If it is not already installed, then:
|
||||
|
||||
#### Chromium Browser
|
||||
|
||||
$ sudo apt install chromium
|
||||
$ sudo apt install chromium-driver
|
||||
|
||||
#### Manager (selenium)
|
||||
Afterwards, selenium is installed:
|
||||
|
128
afu/callbook.py
128
afu/callbook.py
@ -1,115 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
# Thomas Kuschel, following with more ....
|
||||
# changes to python-seleniumbase 4.25/4.27.5-1 python-selenium 4.21.0-1 (installed)
|
||||
# changes:
|
||||
# #001 The Tab URL at phpmyadmin has changed from server_export to server/export
|
||||
# #002 The the visibility of the site is critically, so we have to put in the line option.add_argument('window-size=1200x600')
|
||||
|
||||
import argparse
|
||||
#import datetime
|
||||
import os
|
||||
import time
|
||||
#import re
|
||||
import sys
|
||||
import time
|
||||
|
||||
#import grab
|
||||
# yay extra/python-pip
|
||||
# pip install selenium
|
||||
# ! pip install webdriver-manager
|
||||
# yay geckodriver (for Firefox browser)
|
||||
|
||||
import selenium
|
||||
__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.common.keys import Keys
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.chrome.service import Service as ChromiumService
|
||||
|
||||
__version__ = '2.0.1'
|
||||
def call_description():
|
||||
print(f'Download and Parse the Austrian Callbook Version {__version__}')
|
||||
|
||||
def call_website(url,username,password,server,verbose=0,interactive=False):
|
||||
# using Chrome to access web
|
||||
# driver = webdriver.Firefox(executable_path=r'/usr/bin/geckodriver')
|
||||
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: # do a headless script base work (default)
|
||||
driver=webdriver.Chrome()
|
||||
else:
|
||||
print('Headless Script')
|
||||
service = Service(executable_path='/usr/bin/chromedriver')
|
||||
option = webdriver.ChromeOptions()
|
||||
option.add_argument('headless')
|
||||
option.add_argument('window-size=1200x600')
|
||||
driver = webdriver.Chrome(options=option, service=service)
|
||||
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)
|
||||
assert "phpMyAdmin" in driver.title
|
||||
print(driver.title)
|
||||
elements = driver.find_elements(By.XPATH,'//a[contains(@href,"Rufzeichen")]')
|
||||
|
||||
print('Driver-Title: ' + driver.title)
|
||||
elem = driver.find_element(By.ID, "input_username")
|
||||
elem.clear()
|
||||
elem.send_keys(username)
|
||||
elem = driver.find_element(By.ID, "input_password")
|
||||
elem.clear()
|
||||
elem.send_keys(password)
|
||||
elem = driver.find_element(By.ID, "select_server")
|
||||
from selenium.webdriver.support.ui import Select
|
||||
select = Select(driver.find_element(By.ID, 'select_server'))
|
||||
select.select_by_visible_text(server)
|
||||
driver.find_element(By.ID, "input_go").click()
|
||||
time.sleep(1)
|
||||
#driver.find_element(By.LINK_TEXT, "Export").click()
|
||||
#driver.find_element_by_xpath('//a[contains(@href,"server_export")]').click()
|
||||
#print(driver.page_source.encode("utf-8"))
|
||||
element = driver.find_element(By.XPATH,'//a[contains(@href,"server/export")]')
|
||||
print("Element is visible? " + str(element.is_displayed()))
|
||||
element.click()
|
||||
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.find_element(By.ID, "buttonGo").click()
|
||||
time.sleep(1)
|
||||
print(driver.current_window_handle)
|
||||
|
||||
#w = driver.window_handles[1]
|
||||
#driver.switch_to.window(child)
|
||||
#driver.fullscreen_window()
|
||||
try:
|
||||
# WebDriverWait(browser, 3).until(EC.alert_is_present(),
|
||||
# 'Timed out waiting for PA creation ' +
|
||||
# 'confirmation popup to appear.')
|
||||
alert = driver.switch_to.alert
|
||||
alert.accept()
|
||||
print("alert accepted")
|
||||
except:
|
||||
print("no alert")
|
||||
|
||||
time.sleep(20)
|
||||
driver.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Automates the download of the amateur radio callsign list from Austria',
|
||||
epilog='''
|
||||
Written by Thomas Kuschel,
|
||||
Version {}
|
||||
'''.format(__version__))
|
||||
|
||||
parser.add_argument('--interactive', '-i', action='store_true', default=False)
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
parser.add_argument('--version', action='version', version='{} {}'.format(os.path.split(__file__)[1],__version__))
|
||||
# parser.parse_args(['--version'])
|
||||
parser.add_argument('url', metavar='URL', help='phpMyAdmin login page URL')
|
||||
parser.add_argument('--username', '-u', default='', help='phpMyAdmin login username', required=False)
|
||||
parser.add_argument('--password', '-p', default='', help='phpMyAdmin login password', required=False)
|
||||
parser.add_argument('--server', '-s', default='kreios', required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# call_description()
|
||||
args = call_parser()
|
||||
try:
|
||||
print(f'Try calling {args.url}')
|
||||
filename = call_website(**vars(args))
|
||||
sys.exit(0)
|
||||
except Exception as e:
|
||||
print('Error: {}'.format(e), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print('Verbose level: {}'.format(args.verbose))
|
||||
|
Loading…
Reference in New Issue
Block a user