Refactor file paths and update dependencies

This commit is contained in:
2024-09-25 10:46:37 +09:00
parent 19c2ddc6f5
commit 51a9b4d8c2
6 changed files with 25 additions and 24 deletions

View File

@@ -0,0 +1,3 @@
from .update_dns import DDNS
__all__ = ["DDNS"]

View File

@@ -3,7 +3,7 @@ import logging
import logging.handlers import logging.handlers
import os import os
import sys import sys
from typing import Literal, Optional from typing import Literal
import requests import requests
@@ -259,6 +259,7 @@ class DDNS:
except Exception as e: except Exception as e:
logger.error(f"A RECORDS UPDATE Error: {e}") logger.error(f"A RECORDS UPDATE Error: {e}")
logger.error("Failed to update A records")
sys.exit(5) sys.exit(5)
def update_cname_list(self, cname_list): def update_cname_list(self, cname_list):
@@ -316,26 +317,5 @@ class DDNS:
return True return True
except Exception as e: except Exception as e:
logger.error(f"CNAME RECORDS UPDATE Error: {e}") logger.error(f"CNAME RECORDS UPDATE Error: {e}")
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") logger.error("Failed to update CNAME records")
sys.exit(1) sys.exit(5)
sys.exit(0)

17
run.py Normal file
View File

@@ -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)

View File

@@ -3,4 +3,4 @@
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Run the script # Run the script
python3 $DIR/../src/update_dns.py $@ python3 $DIR/../run.py $@

0
tests/__init__.py Normal file
View File

1
tmp/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
external_ip