From 51a9b4d8c21be2bd9be7dbf53bcb87658cc6c372 Mon Sep 17 00:00:00 2001 From: jung-geun Date: Wed, 25 Sep 2024 10:46:37 +0900 Subject: [PATCH] Refactor file paths and update dependencies --- dynamicdns_ssl/__init__.py | 3 +++ {src => dynamicdns_ssl}/update_dns.py | 26 +++----------------------- run.py | 17 +++++++++++++++++ scripts/run_script.sh | 2 +- tests/__init__.py | 0 tmp/.gitignore | 1 + 6 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 dynamicdns_ssl/__init__.py rename {src => dynamicdns_ssl}/update_dns.py (95%) create mode 100644 run.py create mode 100644 tests/__init__.py create mode 100644 tmp/.gitignore diff --git a/dynamicdns_ssl/__init__.py b/dynamicdns_ssl/__init__.py new file mode 100644 index 0000000..91365da --- /dev/null +++ b/dynamicdns_ssl/__init__.py @@ -0,0 +1,3 @@ +from .update_dns import DDNS + +__all__ = ["DDNS"] \ No newline at end of file diff --git a/src/update_dns.py b/dynamicdns_ssl/update_dns.py similarity index 95% rename from src/update_dns.py rename to dynamicdns_ssl/update_dns.py index 6b03df8..4d05371 100644 --- a/src/update_dns.py +++ b/dynamicdns_ssl/update_dns.py @@ -3,7 +3,7 @@ import logging import logging.handlers import os import sys -from typing import Literal, Optional +from typing import Literal import requests @@ -259,6 +259,7 @@ class DDNS: except Exception as e: logger.error(f"A RECORDS UPDATE Error: {e}") + logger.error("Failed to update A records") sys.exit(5) def update_cname_list(self, cname_list): @@ -316,26 +317,5 @@ class DDNS: return True except Exception as e: logger.error(f"CNAME RECORDS UPDATE Error: {e}") + logger.error("Failed to update CNAME records") sys.exit(5) - - -if __name__ == "__main__": - API = DDNS() - config = API.get_config() - - # Check if the IP has changed - results = API.update_a_list(config["CLOUDFLARE_A"], API.current_ip) - - if not results: - logger.error("Failed to update DNS A records") - sys.exit(1) - else: - API.update_ip(API.current_ip) - - # Update CNAME records - result = API.update_cname_list(config["CLOUDFLARE_CNAME"]) - if not result: - logger.error("Failed to update CNAME records") - sys.exit(1) - - sys.exit(0) diff --git a/run.py b/run.py new file mode 100644 index 0000000..f3b1812 --- /dev/null +++ b/run.py @@ -0,0 +1,17 @@ +import sys +from dynamicdns_ssl import DDNS + + +if __name__ == "__main__": + API = DDNS() + config = API.get_config() + + # Check if the IP has changed + results = API.update_a_list(config["CLOUDFLARE_A"], API.current_ip) + + API.update_ip(API.current_ip) + + # Update CNAME records + result = API.update_cname_list(config["CLOUDFLARE_CNAME"]) + + sys.exit(0) diff --git a/scripts/run_script.sh b/scripts/run_script.sh index 70fb5fe..bbb3dba 100755 --- a/scripts/run_script.sh +++ b/scripts/run_script.sh @@ -3,4 +3,4 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Run the script -python3 $DIR/../src/update_dns.py $@ \ No newline at end of file +python3 $DIR/../run.py $@ \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tmp/.gitignore b/tmp/.gitignore new file mode 100644 index 0000000..c12e6dd --- /dev/null +++ b/tmp/.gitignore @@ -0,0 +1 @@ +external_ip \ No newline at end of file