#!/usr/bin/env python

import argparse, pdb, simpledaemon, time
import pscripts.external_ip_address as eia

eia.yaml_file='/etc/external_ip_updater/urls.yaml'
eia.ip_cache_file='/tmp/.current_external_ip'

class ExtIpUpdaterDaemon(simpledaemon.Daemon):
    default_conf = '/etc/external_ip_updater/config.conf'
    section = 'external_ip_updater'

    def run(self):
        refresh_period_seconds = int(eia.get_yaml_setting("refresh_period_seconds"))
        eia.flush_ip_cache_file()
        while True:
            eia.update_ddns_server()
            time.sleep(refresh_period_seconds)

if __name__ == '__main__':
    ExtIpUpdaterDaemon().main()
