Skip to content

Commit

Permalink
cfst: 更新cfip和cfipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
laityts committed Feb 1, 2025
1 parent dd739e3 commit 9bf638d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
11 changes: 10 additions & 1 deletion cfip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
import re
import os
import logging
from datetime import datetime
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from colo_emojis import colo_emojis # 确保colo_emojis.py存在并正确导出字典

# 获取当前时间并格式化为文件名
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
log_filename = f'logs/cfip_{current_time}.log'

# 确保日志目录存在
os.makedirs('logs', exist_ok=True)

# 删除旧的日志文件(如果存在)
if os.path.exists(log_filename):
os.remove(log_filename)

# 配置日志记录
logging.basicConfig(
filename='logs/error.log', # 日志文件路径
filename=log_filename, # 日志文件路径
level=logging.ERROR,
format='%(asctime)s - %(levelname)s - %(message)s'
)
Expand Down
14 changes: 12 additions & 2 deletions cfipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from datetime import datetime
import subprocess
import glob

# 从 colo_emojis.py 导入 colo_emojis 字典
from colo_emojis import colo_emojis
Expand All @@ -13,8 +14,17 @@ def setup_logging():
log_dir = "logs" # 日志文件夹名称改为 log
os.makedirs(log_dir, exist_ok=True)

# 日志文件名格式:YYYY-MM-DD.log
log_file = os.path.join(log_dir, f"{datetime.now().strftime('%Y-%m-%d')}.log")
# 删除旧的日志文件
old_logs = glob.glob(os.path.join(log_dir, "cfipv6*.log"))
for old_log in old_logs:
try:
os.remove(old_log)
logging.info(f"Deleted old log file: {old_log}")
except Exception as e:
logging.error(f"Error deleting old log file {old_log}: {e}")

# 日志文件名格式:cfipv6_YYYY-MM-DD_HH-MM-SS.log
log_file = os.path.join(log_dir, f"cfipv6_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log")

# 配置日志
logging.basicConfig(
Expand Down
1 change: 1 addition & 0 deletions ddns/autoddnsipv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import logging
import sys
import re

# 配置日志
logging.basicConfig(
Expand Down
2 changes: 2 additions & 0 deletions logs/2025-02-01.log
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
2025-02-01 09:18:42,493 - INFO - Processed address: [2606:4700:3036:ef:db9e:eecc:caef:9d4a]#🇭🇰HKG┃CMCC-IPV6
2025-02-01 09:18:42,645 - INFO - Processed address: [2606:4700:3036:6ed4:e1ed:36:7204:2031]#🇭🇰HKG┃CMCC-IPV6
2025-02-01 09:18:42,651 - INFO - Processed IPv6 addresses have been written to cfip/cfipv6.txt
2025-02-01 09:18:46,711 - INFO - Changes have been pushed to GitHub.
2025-02-01 09:18:46,712 - INFO - Script finished.

0 comments on commit 9bf638d

Please sign in to comment.