Compare commits

...

2 Commits

Author SHA1 Message Date
Jean-Claude a2999c3d93 Merge branch 'feature/allow-specifying-domain' of jonas/DynDns into master 2020-12-19 14:50:48 +01:00
Jonas Sulzer 495dbbe3dc
👌 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>
2020-12-19 11:54:05 +01:00
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()