👌 IMPROVE: allow specifying the domain to update

this allows DynDNS to be used against Hostpoint accounts with multiple domains
the domain to update is to be configured via the .env variable 'Domain'

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
This commit is contained in:
Jonas Sulzer 2020-12-18 23:55:25 +01:00
parent 67d8eda971
commit 495dbbe3dc
Signed by untrusted user: jonas
GPG Key ID: 6D1DC8E0D9904C83
2 changed files with 18 additions and 2 deletions

View File

@ -1,2 +1,3 @@
HpLogin=
HpPass=
Domain=

View File

@ -9,6 +9,9 @@ from pyvirtualdisplay import Display
logger = logging.getLogger(__file__)
class DomainNotFoundError(Exception):
pass
class HpUpdater():
def __init__(self):
@ -26,7 +29,16 @@ class HpUpdater():
logger.debug('updateARecord called')
driver.get('https://admin.hostpoint.ch/customer/Domains/Overview')
driver.find_element_by_name('edit_dns').click()
domainTableRows = driver.find_elements_by_class_name('b-table__body-row')
for row in domainTableRows:
if os.environ.get('Domain') == row.find_element_by_class_name('domain-name-value').get_attribute('value'):
row.find_element_by_name('edit_dns').click()
logger.debug('domain found')
break
else:
raise DomainNotFoundError(f'Domain {os.environ.get("Domain")} can not be found in domain list.')
driver.implicitly_wait(10)
@ -84,7 +96,10 @@ class HpUpdater():
logging.info('Initialized firefox browser..')
self._login(driver)
self._updateARecord(driver, ip)
try:
self._updateARecord(driver, ip)
except DomainNotFoundError as e:
logging.error(e)
driver.quit()
display.stop()